@@ -446,7 +446,7 @@ TCP echo client example, send data and wait until the connection is closed::
446446
447447 import asyncio
448448
449- class EchoClient (asyncio.Protocol):
449+ class EchoClientProtocol (asyncio.Protocol):
450450 message = 'This is the message. It will be echoed.'
451451
452452 def connection_made(self, transport):
@@ -461,7 +461,7 @@ TCP echo client example, send data and wait until the connection is closed::
461461 asyncio.get_event_loop().stop()
462462
463463 loop = asyncio.get_event_loop()
464- coro = loop.create_connection(EchoClient , '127.0.0.1', 8888)
464+ coro = loop.create_connection(EchoClientProtocol , '127.0.0.1', 8888)
465465 loop.run_until_complete(coro)
466466 loop.run_forever()
467467 loop.close()
@@ -481,7 +481,7 @@ TCP echo server example, send back received data and close the connection::
481481
482482 import asyncio
483483
484- class EchoServer (asyncio.Protocol):
484+ class EchoServerClientProtocol (asyncio.Protocol):
485485 def connection_made(self, transport):
486486 peername = transport.get_extra_info('peername')
487487 print('Connection from {}'.format(peername))
@@ -498,7 +498,8 @@ TCP echo server example, send back received data and close the connection::
498498 self.transport.close()
499499
500500 loop = asyncio.get_event_loop()
501- coro = loop.create_server(EchoServer, '127.0.0.1', 8888)
501+ # Each client connection will create a new protocol instance
502+ coro = loop.create_server(EchoServerClientProtocol, '127.0.0.1', 8888)
502503 server = loop.run_until_complete(coro)
503504
504505 # Server requests until CTRL+c is pressed
@@ -575,7 +576,7 @@ method, send back received data::
575576
576577 import asyncio
577578
578- class EchoServerClientProtocol :
579+ class EchoServerProtocol :
579580 def connection_made(self, transport):
580581 self.transport = transport
581582
@@ -587,8 +588,9 @@ method, send back received data::
587588
588589 loop = asyncio.get_event_loop()
589590 print("Starting UDP server")
591+ # One protocol instance will be created to serve all client requests
590592 listen = loop.create_datagram_endpoint(
591- EchoServerClientProtocol , local_addr=('127.0.0.1', 9999))
593+ EchoServerProtocol , local_addr=('127.0.0.1', 9999))
592594 transport, protocol = loop.run_until_complete(listen)
593595
594596 try:
0 commit comments