问题
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