TcpListener - how to start server with global ip address

邮差的信 提交于 2019-12-08 14:00:02

问题


I would start TcpListener server with my global IP address. I have open ports and using DMZ and my port 8074 is available and i should be able to start this server.

My code looks like :

IPAddress ip = IPAddress.Parse("XX.XXX.XX.XXX.XX");
TcpListener server = new TcpListener(ip, Convert.ToInt32(8888));
TcpClient client = default(TcpClient);
try
{
    server.Start();
    Console.WriteLine("Server started...");
}
catch (Exception ex)
{
    Console.WriteLine(ex.ToString());
};

And all the time i have Error looks like:

Activated Event Time Duration Thread Exception: An exception was thrown: "System.Net.Sockets.SocketException" in System.dll ("The requested address is different in this context"). An exception was thrown: "System.Net.Sockets.SocketException" in System.dll ("The requested address is different in this context") 5.52s [5780] Worker thread

You can check if you want this port is accessible on my IP address but can't start server on this.


回答1:


Yeah thanks @jdweng . All i need to change was just this lane :

IPAddress ip = IPAddress.Any;


来源:https://stackoverflow.com/questions/51469037/tcplistener-how-to-start-server-with-global-ip-address

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!