I am a newbie in python sockets and am really troubled by the stubbornness of the socket.accept() method. I really need a way of ending a socket.accept() method or any other alternative to socket.accept() which runs one time only. Plzzzz somebody help.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
You have several options here:
- Close the listening socket from another thread - the
accept()
will raise an exception if it fails. - Open a local connection to the listening socket - that makes the
accept()
return by design. - Use an accept mechanism that can block on more than one synchronization object so that the wait can be signaled to return without a connection.
- Use a non-blocking alternative to
accept()
, (async likeAcceptEx()
and overlapped IO on Windows).