i made basic TCP Socket server and client console application in c# with listener etc.. it works well with both server and client executed in same machine(127.0.0.1:10048). I want to try it with different machines in same network(both connected to same modem). Which ip port should i use? I need help. Thanks
2 Answers
You should use a port in the ephemeral port range. The ephemeral port range is the range of port numbers that is being selected from if you active connect to a server. The point is that it is free for use. Your kernel will skip the port numbers that are already in use so you don't have to worry about that either.
http://en.wikipedia.org/wiki/Ephemeral_port
And on top of this it is best not to hardcode your port numbers and ip adresses where you bind to connect or send to.
Make sure your OS firewall is turned off. For instance windows firewall can block this type of traffic.
Do not use just any free port that you detect is not in use. For instance you may not have an FTP or Telnet server running on your system, but that does not mean that you can just hijack those ports. From a functional point of view it will work if you do, but then you cannot run those services anymore somewhere in the future where you might need them, or your application will start failing. Which fails depends on which application is first started and starts using the port first.
When you bind an ip@ you should use INADDR_ANY. Loopback communication will still work if you use this, you probably already did, most examples include it. Sending or connecting to an IP@ should come from a configuration file (data driven) or commandline parameters. The IP@ depends of course on the machine you want to communicate with.
- 7,344
- 3
- 28
- 39
-
thanks for your answer. i've successfully transferred data(char, string etc.) but when i try to write file bytes(trying file transfer) it blocks. am i supposed to do different work for file transfer or port forwarding in modem page? – Kor Sar May 17 '15 at 09:41
-
port forwarding is only needed if you want your server to be accessible from outside your local network. – Philip Stuyck May 17 '15 at 10:07
-
Okey. Thanks again. done it with using different ephemeral port(50101). Now i have 2 port and 2 different connections. But no problem. – Kor Sar May 17 '15 at 10:52
Open your CMD and type ipconfig. There you can see your IPv4 address, that you should use to connect. The port doesn't really matter. Make sure to turn of your firewall(s) to allow a connection
- 1,244
- 8
- 21