是否可以AcceptSocket
对TcpListener
具有超时的对象进行一次中断?
TcpListener server = new TcpListener(localIP, port);
server.Start();
while (!shuttingDown)
try
{
Socket client = server.AcceptSocket();
if (client != null)
{
// do client stuff
}
}
catch { }
尝试 BeginAccept 和 EndAccept:如果 3 秒内没有客户端,我该如何结束接受?(我试图在这里近似解决方案)
server.BeginAcceptTcpClient(new AsyncCallback(DoAcceptTcpClientCallback), server);
Thread.Sleep(3000);
server.EndAcceptTcpClient(???);