diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2013-12-03 14:04:18 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2013-12-03 14:04:18 (GMT) |
commit | 15faa9c8ad1833cea964281e70085a603365a75a (patch) | |
tree | 618f14cbdc8537947ba83a8f900a01eefd63e3b1 /Doc/library | |
parent | 153b894fdc9e40b6f067a6177c08017a67dc2a7d (diff) | |
download | cpython-15faa9c8ad1833cea964281e70085a603365a75a.zip cpython-15faa9c8ad1833cea964281e70085a603365a75a.tar.gz cpython-15faa9c8ad1833cea964281e70085a603365a75a.tar.bz2 |
asyncio doc: simplify ping example, remove the useless timeout
Diffstat (limited to 'Doc/library')
-rw-r--r-- | Doc/library/asyncio-protocol.rst | 10 |
1 files changed, 3 insertions, 7 deletions
diff --git a/Doc/library/asyncio-protocol.rst b/Doc/library/asyncio-protocol.rst index e3a5656..5182df5 100644 --- a/Doc/library/asyncio-protocol.rst +++ b/Doc/library/asyncio-protocol.rst @@ -589,25 +589,21 @@ TCP echo server example:: import asyncio class EchoServer(asyncio.Protocol): - def timeout(self): - print('connection timeout, closing.') - self.transport.close() - def connection_made(self, transport): print('connection made') self.transport = transport - # close the client connection after 2 seconds - asyncio.get_event_loop().call_later(2.0, self.timeout) def data_received(self, data): print('data received:', data.decode()) self.transport.write(data) + # close the socket + self.transport.close() + def connection_lost(self, exc): print('connection lost') - loop = asyncio.get_event_loop() f = loop.create_server(EchoServer, '127.0.0.1', 8888) s = loop.run_until_complete(f) |