简体   繁体   English

是否socket.listen(0); 暂停线程?

[英]Does socket.listen(0); pause a thread?

I am thinking of having socket.listen() on a separate thread for my server, does it pause the thread? 我正在考虑在服务器的单独线程上使用socket.listen(),它会暂停线程吗?

I want to have my thread to listen, talk with the client, end client connection, listen again. 我想让我的线程收听,与客户端交谈,结束客户端连接,再次收听。

The Listen method does not block the current thread, it merely sets up the Socket to accept new connections. Listen方法不会阻塞当前线程,它只是将Socket为接受新连接。 Methods like Accept in synchronous mode will block the thread until a connection is received. 诸如同步模式下的Accept方法将阻塞线程,直到接收到连接为止。

Note: The MSDN documentation for methods on Socket are pretty good about listing whether or not they block in the Remarks section. 注意:有关Socket方法的MSDN文档非常适合在“备注”部分中列出它们是否受阻。 Example

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM