[英]How do I do an AcceptAsync of a socket with a timeout?
Here is what I have now: 这是我现在所拥有的:
Socket myNewSocket = currentSocket.Accept();
Here is what I want: 这是我想要的:
Socket myNewSocket = AcceptWithTimeout(currentSocket, timeoutInMilliseconds)
You could do a BeginAccept
and then have a timer that closes the socket to cancel the accept operation. 您可以执行
BeginAccept
,然后使用一个计时器来关闭套接字以取消接受操作。 Usually, though, servers just keep an asynchronous accept operation going constantly. 通常,尽管如此,服务器只是保持异步接受操作不断进行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.