client server app upnp / port forward question - c#

I am thinking about writing a client server app using sockets in c#. My question is, if the server is behind a router and upnp is enabled, once the server starts listening does upnp automatically forward data incoming to that computer if it is destined for said port? I don't want the user to have to start forwarding ports, I am hoping my server app can be zero configuration.
Thanks in advance.

I worked on a uPNP tool a little while ago for a work application for file sharing across multiple sites.
I can confirm that during the port configuration via uPNP, that you do indeed specify which port and end point you would like to listen.
If uPNP reports back OK. All requests to the port will be forwarded to the passed end point.
I will find the class I made \ modified and give it as an example shortly....

Related

Two-way Communication between Server and Clients

Situation: We have a web application running on a server. This application needs to fetch data from some other PC(Clients), which are on a different network.
On the clients' pc there are WCF hosted in Windows Services using its their local Sql db. i want to make duplex communication between server and clients for share data with each other.
data share mean share data-table,data-set,string etc between clients and server .
Problem :
1) I have no control over the firewall, proxy, NAT on the client side PC. Mostly company Employee PCs have lots of network security e.g firewall block ICMP traffic and some port too, some Router might be Disabled port-forwarding etc etc , client can change network place.
I don't want to make any setting on client side Router,proxy,firewall though .
during communication how can i handle that's kind of issue of client side?
as you know skype is working perfect in that situation.
firewalls very often block inbound connections to clients; the client may not be reachable from the server, it may be using NAT translation behind a router and so cannot be contacted without port forwarding being set up on the router and some new router disabled port forwarding .
2) On clients side there is no IIS .
I don't want to allow remote access on clients PC.
There are more than 100 Clients and only one Server. one server need communicate with many clients on different network .
3) One side my client application is using window application and wcf hosted in window service ,Other side on my server i'm using Web application . so its mean communication is between desktop pc and web pc , that's issue .
If both using a web application then it was not issue to make duplex communication.because i know WEBRTC is fit there lol.
Technology which i had already test and find issue
WSDualHttpBinding: Not work if client behind NAT. check this for detail click here
MSMQ : its bad technique if clients more than 1 and performance issue also because its use RAM memory . check here click here
Xsocket: Its also not work if ICMP traffic block by firewall on client. check here click
WebRTC: Its work fine but its support web to web communication .as my client side i have win app.
Socket.io: Its need to set up node.js and many other thing , hard to implement because i need implement on existence application , i am not making new application.
C# Socket Program: Its wouldn't work if client behind NAT.check here click for detail
Service Bus relay: Its not free even for testing .
socketPro: I studied i find its good but i can't find any right sample on google .so that i could test that.
Genuine Channels: I can't find any sample on google .
Lets see SignalR issue .: Server side i run a console application and Client side i run two application ,one is console and other web. when i was running console client application than it was not initiating connection with Server but when i was using web client application then it was working fine.
sample link is here SignalR two way communication
I can't understand why thas??
Please tell me What is best most secure and fast way to handle this situation? what approach should i use ?
SignalR seems to fit for this solution, because it's flexible.
It negotiates the fastest available channel of communication and that is what you are looking for.
You should investigate the problem with it and signalR will eventually work.
I'm using SignalR extensively to communicate between the servers (C#), between server and mobile apps (C#, Xamarin, iOS, Android). The servers are at different locations and the mobile apps can be anywhere. It all works very reliable.
Take a look at: http://www.asp.net/signalr/overview/deployment/tutorial-signalr-self-host and here http://www.asp.net/signalr/overview/guide-to-the-api/hubs-api-guide-net-client
I've been working in my spare time with sockets (admittedly in c++, not c# but there shouldn't be a difference), and I've never had an issue connecting to clients behind a firewall/router, even without port forwarding.
Routers and firewalls generally don't like server-like programs, eg. programs that bind the socket to a port number. Does your client do anything related to binding? Because it shouldn't.
Needless to say, I would suggest a socket program. The way I see it, it's the most flexible way.

C# TcpListener external IP

I'm creating a TcpListener, and I want clients from other computers to be able to join my listener.
I've read and understood that I have to do Port Forwarding, but it doesn't make any sense to me - when I publish my app, I want other people to create this Listener, and I can't tell them to do Port Forwarding.
Is there any possibility to create a TcpListener that clients will be able to join without Port Forwarding?
Thank you.
Well, lets try to clear somethings out first.
The main reason to use port forwarding is because you have a NAT router in front of an internal network. To setup a port forward is to instruct the NAT router to forward traffic to a certain port on the public interface to a port on an internal computer.
If you don't have a NAT router you don't need port forwarding.
Many routers today support UPnP, a technique to kindly ask the router to create a specific port forward. A suitable library to use might be ManagedUPnP.
However you still need to figure out the public IP of the router and what port you have opened and communicate that to your other applications.
If your router does not allow UPnP or there are other fire wall rules in place you can not set up a port forwarding correctly.
You can create server application and forward ports on your pc. Client application (this one you will publish) will just connect to your pc so they can be on the NAT. You can also combine your application with some php/asp pages but it depends on data you would like to send. If it's some kind of PC statistics like uptime, hardware etc. you would just use http query in client app to website script you've created (for instance mypage.com/?uptime=100&ram=2gb&hash=xxxx etc.)
Only the server (the computer which is accepting TCP requests) needs to have the port forwarded.
The common model is that you (the developer/producer of the service) host the server. Then customers (people who subscribe to your service) connect to your service using either an IP or a URL. If your service is behind a firewall (you have a router between your computer and your internet modem) then you will have to forward the port. You will probably also have to open the port in Window's firewall, but I expect you have done this already. In this model the customer does not have to do anything with their router (it is like using a web browser).
If you are making a product where your customers are hosting the service then they will have to deal with the port issues. In which case you could try ManagedUPnP like Albin Sunnanbo suggests or redirect them to one of the many sites explaining how to setup port forwarding.

Sockets: client finding server automatically via name, not IP

I got a client program in Java (Android app), and a server program in C#.
They communicate via Sockets over an internal network.
Problem:
The client needs to have the server's IP address stored, to be able to connect. So, the server needs a static IP.
But now I got to a point I can't have a static IP anymore, so the client has to find the server when it starts up, somehow.
I thought you could use the computer-name to connect via Sockets, but that didn't work for me.
Then I had an idea to just do a broadcast with a basic request, and see who answers (the server from the correct IP), but I have no idea how I can do a broadcast and wait for multiple responses.
And then I also have to find the broadcast address.
Are there any techniques out there that I don't know and haven't come across yet?
Any help is much appreciated! :)
What you are looking is a hostname discovery service. JNDI is an API for discovering hostnames, but it is for java applications.
check this documentation how to use JNDI from .NET framework

Port forwarding on Windows 7

How do I redirect an incomming request on port xxx to localhost:yyy on windows 7?
Development Server (vs 2008) only allow access from localhost which isnt good enough. I need to test my app from various computers.
Thanks for the suggestions guys, although I found the answer myself.
I downloaded Microsoft SOAP Toolkit version 3 and started MSSoapT, created a formatted trace listening on port 8080, forwarding to host: 127.0.0.1 port: 3804. My problem was I used "localhost" and not "127.0.0.1".
Now every request made to my development machine from other computers through port 8080 will be redirected to port 3804 where ASP.NET Development Server is statically set to listen when debugging VS.NET webapps.
On the command prompt.
$> netsh
$> interface portproxy
$> add v4tov4 listenport=xxx connectaddress=127.0.0.1 connectport=yyy protocol=tcp
See: http://technet.microsoft.com/en-us/library/cc776297%28WS.10%29.aspx#BKMK_1
If this really is for some testing, you could create a server which listens on a port, and when it receives an incoming connection spawns a thread that opens a connection to the actual local server, and afterward just waits for data to come in either end and shuffle it along to the other end. If either socket closes, the worker thread would terminate. This is obviously not a scalable solution, but for testing it should easily do the trick.
Not really sure what you are looking for. However port forwarding will be relevant when you have a router in place and you need to explicitly forward a request on a specific router port to a specific IP and port on a LAN computer. If you want to access the web server from other LAN computers on the same network then http://ip-address should just work fine. Also make sure that your web server is listening on the LAN IP and is not just bound to localhost.
I'm using windows 7 64 bit and couldn't get the Microsoft SOAP Toolkit to work on my machine for port forwarding and didn't like the free port forwarding software I found out there so I just changed my VS 2010 web app to use local iis, I know this doesn't help people running 2008 but it works if you have 2010... Here's a screen shot of my change: I'm doing this for testing on the iPad...

sending data to the server via port 5555 C#

I am wanting to send some data to a server from a client application to the server via port 5555. I don't have a window's server. My question is if I purchase a .Net Framework hosting service. Would I be able to connect the client application to this server. and could I do it by sending a Post. I am new to this, so excuse me if it doesn't entire make sense. but I am looking for just some little direction. If someone could explain what port 5555 is used for that would be great.
Most hosting provides will only allow incoming connections on the standard web ports (80 for unencrypted traffic/http and 443 for encrypted/https). Outgoing connections are less likely to be restricted, but it is not uncommon that only a few specific ports are open.
If you're developing a custom solution and you do not need a connection that allows you to continually send data back and forth, then a hosted solution will do fine. If you do need the live link or custom port numbers then you'll need to upgrade to a virtual managed server, which is essentially your own virtual copy of a Windows server. This costs more but allows you to listen on custom ports - essentially do as you please.
As for determining the specific use of a port, most networked applications have simply picked one or more numbers without much research. IANA maintains a list of protocols/applications/services and their associated port numbers, but being listed requires that an application is sent and approved.
Custom port for data exchange + tcp/ip has been identified to be very difficult across the Internet, due to firewalls/gateways everywhere.
Why not use REST web service or SOAP web service for data exchange? That has been proved to be a firewall friendly approach as it uses port 80 or 443.

Categories