Saturday, October 2, 2010

Selection of the Right IP Addresses for the Communication over TCP / IP

In the previous post I described, how to exchange data over the TCP / IP protocol using C#.
The method describes there works as well for the internet as the local network. In this post I want to explain quickyl, which IP addresses to use.

If server and client are in the same local network, the client can jan just use the local network IP of the server. In a local network every computer has a unique IP, mostly of the form 192.168.xxx.xxx.

If the onnection should take place over the internet, the so called WAN IP has to be used. This can for example be determined via the site http://www.wieistmeineip.de/ (to get it with C#, see this post).
The problem though is, that this address is just unique for all access points to the internet. However, nowadays most households have an internet connction over a router, to which multiple computers are connected to. That means only the router gets a WAN IP, all connected computers share these.
So if the connection over the internet does not work, the reason might be that the router does get the connection request of the client, but does not know, to which computer in the network to forward it to.
Therefor, in the router a new rule for Port Forwarding has to be created. These rules then tell the router, to which computer data incoming on specific ports to forward to.
If you now create a rule for the port the server is listening at and forward this port to the IP address of your own computer in the local network, the TCP / IP connection also works over the internet.

No comments:

Post a Comment