我的TCPListener配置是这样的:的TCPListener蓝调,想不通为什么连接不正确关闭
this.tcpListener = new TcpListener(IPAddress.Any, config.portNum);
然后我(使用线程)设置一个监听器函数是这样的:
private void ListenForClients()
{
this.tcpListener.Start();
while (true)
{
//blocks until a client has connected to the server
TcpClient client = this.tcpListener.AcceptTcpClient();
//create a thread to handle communication
//with connected client
ThreadStart starter = delegate { HandleClientComm(client, this.DBGrid); };
Thread thread = new Thread(starter);
thread.Start();
}
}
围绕它的作品第一次,第二次我火了,我得到这个错误信息:
每个套接字地址(协议/网络地址/端口)的一个用法通常 允许
线程里面有一个叫关闭:
tcpClient.Close();
但它似乎并没有释放该端口了,有什么建议?
您获得这种怀疑的特定代码行是什么? – user957902
this.tcpListener.Start();第二次造成问题。 –
您是否在同一个进程中多次调用tcpListener.Start,或者一旦关闭了进程并重新启动它,就会出现错误? – user957902