开发者

tcp/ip connection with anonymous client IP

I'm creating a tcp/ip system using VS2010,C#, I'm going to setup a server program in my Server PC (win2008R2), I've opened port 2020 and now I can send data to this port using my GSM/GPRS modems, I have a small problem relates to clients ip address, in my server I should specify an IP address for listening, I have several modems which will be used as my clients, they may be turned off/on, so I don't know anything about their IP, how can I know IP port to listen for? I should use IPAddress.Any? what are my options? I've used a test server program which can receive data from any client IP address, how does this program do 开发者_Go百科so? how can it detect client IP? is there any sample or tutorial showing this? thanks


I assume you're using TcpListener, and are referring to the IPAddress parameter to the constructor. That isn't a client IP; it's the server's own IP address that you want to listen on. You really only need to specify it if the server has multiple network interfaces (or multiple IPs on a single interface) and you only want to accept connections on one of them. If you want to bind to all of the server's IPs, then use IPAddress.Any.

Check out the Remarks on http://msdn.microsoft.com/en-us/library/c6z86e63.aspx for some more special cases for those parameters.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜