客户端中的Python asyncore.loop
我在谷歌上搜索了很多文章,但仍然没有重要的信息 我的问题是如何在客户端停止asyncore.loop() 我的代码如下 导入套接字,异步客户端中的Python asyncore.loop,python,sockets,asyncore,Python,Sockets,Asyncore,我在谷歌上搜索了很多文章,但仍然没有重要的信息 我的问题是如何在客户端停止asyncore.loop() 我的代码如下 导入套接字,异步 class Client(asyncore.dispatcher): def __init__(self, host, port): self.buffer = '' asyncore.dispatcher.__init__(self) self.create_socket(socket.AF_INET
class Client(asyncore.dispatcher):
def __init__(self, host, port):
self.buffer = ''
asyncore.dispatcher.__init__(self)
self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
self.connect((host, port))
def writable(self):
return len(self.buffer) > 0
def handle_connect(self):
print "handle_connect"
def handle_close(self):
print "handle_close"
self.close()
def handle_write(self):
print "handle_write"
sent = self.send(self.buffer)
self.buffer = self.buffer[sent:]
print sent
def command(self, data):
self.buffer = data
def close(self):
self.close()
mysocket = Client("127.0.0.1", 8888)
mysocket.command("asfas\n")
asyncore.loop()
mysocket.close()
提前谢谢 为什么需要停止循环?您想在停止后完成一些操作吗?请参阅-我认为,这将对您有所帮助谢谢您的评论@Dmitry。我需要它,因为这是客户端,在运行命令之后,客户端脚本应该退出。您的第二条评论是针对服务器端的。