赞
踩
asyncio.Protocol socket 断线重连
原文:https://www.jianshu.com/p/f5bc755d3d8a
- import asyncio
-
-
- class EchoServerClientProtocol(asyncio.Protocol):
- def connection_made(self, transport):
- peername = transport.get_extra_info('peername')
- print('Connection from {}'.format(peername))
- self.transport = transport
-
- def data_received(self, data):
- message = data.decode()
- print('Data received: {!r}'.format(message))
-
- message = "Hello Client"
- self.transport.write(data)
- self.transport.close()
-
-
- loop = asyncio.get_event_loop()
- # Each client connection will create a new protocol instance
- coro = loop.create_server(EchoServ

Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。