我有以下问题:
一旦我关闭我的 WM6 应用程序,然后尝试再次启动它,我就会收到此错误: System.Net.Sockets.Socket.Bind(EndPoint localEP) 通常只允许使用每个套接字地址(协议/网络地址/端口)在 System.Net.Sockets.Socket.TcpListener.Start() ...
我认为这是由于连接超时的时间间隔,所以我想关闭所有打开的连接并强制它创建一个新的连接,这是正确的方法还是有不同的方法来处理这个?
这是用于开始收听的代码:
/// <summary>
/// Listens Asynchronously to Clients, creates a recieveMessageHandler to process the read.
///
/// Check WIKI, TODOS
/// </summary>
/// <returns></returns>
public void Listen()
{
myTcpListener.Start();
while (true)
{
//blocks until a client has connected to the server
try
{
TcpClient myTcpClient = myTcpListener.AcceptTcpClient();
DateTime now = DateTime.Now;
//Test if it's necessary to create a client
ClientConnection client = new ClientConnection(myTcpClient, new byte[myTcpClient.ReceiveBufferSize]);
// Capture the specific client and pass it to the receive handler
client.NetworkStream.BeginRead(client.Data, 0, myTcpClient.ReceiveBufferSize, r => receiveMessageHandler(r, client), null);
}
catch (Exception excp)
{
Debug.WriteLine(excp.ToString());
}
}
}