0

如何释放 TCPListener 使用的 .NET 中的端口......在 TCPListener 收到所需的东西之后

4

2 回答 2

2

Just call the Stop-method on the TcpListener.

于 2009-08-22T12:39:28.483 回答
0

我们首先建立了第一个Socket:

     Socket socket1; 
     IPEndPoint localEP = new IPEndPoint (IPAddress.Any, 20000); 
     Socket1 = new Socket (AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); 
     Socket1.Bind (localEP); 

然后是第二个套接字:

     Socket socket2 
     IPEndPoint localEP = new IPEndPoint (IPAddress.Any, 20000); 
     Socket2 = new Socket (AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); 
     Socket2.SetSocketOption (SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true); 
    / / Please note this one. True ReuseAddress options will be set to allow the socket to bind already in use in the address. 
     Socket2.Bind (localEP); 

这样就将 Socket1 和 Socket2 捆绑在同一个端口上了。

于 2009-08-22T12:30:16.767 回答