python 异步连接
有没有办法检查 asyncore 中是否建立了连接?
一旦调用 asyncore.loop() ,如何断开服务器之间的通信?
我可以简单地调用 close() 吗?
is there a way to check connection is established in asyncore?
once asyncore.loop() is called, how can I disconnect the communication between server?
can i just simply call close()?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一旦调用 asyncore.loop(),控制权就会移交给运行的事件循环。
asyncore.loop() 之后的任何代码只有在事件循环关闭后才会被调用。
事件循环将对各种事件做出反应并调用处理程序。 要关闭事件循环,您必须在有意义的事件处理程序之一中调用 stop。
例如:请看以下示例。
代码来自: http://www.mechanicalcat.net/richard/log/Python/A_simple_asyncore__echo_server__example< /a>
self.close 在事件处理程序之一 -handle_read 内调用。在这种情况下,从服务器接收到数据后。它会自行断开连接。
参考文献:
Once asyncore.loop() is called, the control is handed over to event loop that runs.
Any code after the asyncore.loop() will be called only after the event loop has been shut down.
Event loop will react to various events and call handlers. To shutdown the event loop, you must call to stop in one of the event handler where it makes sense.
For ex: Take a look at the following example.
Code from : http://www.mechanicalcat.net/richard/log/Python/A_simple_asyncore__echo_server__example
self.close is called inside one of the event handler - handle_read. In this case after the data has been received from the server. it disconnects itself.
References:
与套接字一起使用,您可以重载asyncore的handle_connect()方法。当套接字连接时调度程序运行:
如果您更喜欢轮询,请读取 asyncore.dispatcher 中的变量 connected :
Using with sockets, you can overload handle_connect() method of asyncore.dispatcher to run when socket is connected:
If you prefer polling, read the variable connected in your asyncore.dispatcher: