asyncio doc: simplify ping example, remove the useless timeout

This commit is contained in:
Victor Stinner 2013-12-03 15:04:18 +01:00
parent 153b894fdc
commit 15faa9c8ad
1 changed files with 3 additions and 7 deletions

View File

@ -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)