]> granicus.if.org Git - python/commitdiff
asyncio doc: clarify how servers create protocol instances
authorVictor Stinner <victor.stinner@gmail.com>
Sun, 12 Oct 2014 09:30:17 +0000 (11:30 +0200)
committerVictor Stinner <victor.stinner@gmail.com>
Sun, 12 Oct 2014 09:30:17 +0000 (11:30 +0200)
Doc/library/asyncio-protocol.rst

index d2f1369de1009908c36306ee812ec1f913b916c6..66524c1c1815bd83e93e493271115c227bf1508f 100644 (file)
@@ -446,7 +446,7 @@ TCP echo client example, send data and wait until the connection is closed::
 
     import asyncio
 
-    class EchoClient(asyncio.Protocol):
+    class EchoClientProtocol(asyncio.Protocol):
         message = 'This is the message. It will be echoed.'
 
         def connection_made(self, transport):
@@ -461,7 +461,7 @@ TCP echo client example, send data and wait until the connection is closed::
             asyncio.get_event_loop().stop()
 
     loop = asyncio.get_event_loop()
-    coro = loop.create_connection(EchoClient, '127.0.0.1', 8888)
+    coro = loop.create_connection(EchoClientProtocol, '127.0.0.1', 8888)
     loop.run_until_complete(coro)
     loop.run_forever()
     loop.close()
@@ -481,7 +481,7 @@ TCP echo server example, send back received data and close the connection::
 
     import asyncio
 
-    class EchoServer(asyncio.Protocol):
+    class EchoServerClientProtocol(asyncio.Protocol):
         def connection_made(self, transport):
             peername = transport.get_extra_info('peername')
             print('Connection from {}'.format(peername))
@@ -498,7 +498,8 @@ TCP echo server example, send back received data and close the connection::
             self.transport.close()
 
     loop = asyncio.get_event_loop()
-    coro = loop.create_server(EchoServer, '127.0.0.1', 8888)
+    # Each client connection will create a new protocol instance
+    coro = loop.create_server(EchoServerClientProtocol, '127.0.0.1', 8888)
     server = loop.run_until_complete(coro)
 
     # Server requests until CTRL+c is pressed
@@ -575,7 +576,7 @@ method, send back received data::
 
     import asyncio
 
-    class EchoServerClientProtocol:
+    class EchoServerProtocol:
         def connection_made(self, transport):
             self.transport = transport
 
@@ -587,8 +588,9 @@ method, send back received data::
 
     loop = asyncio.get_event_loop()
     print("Starting UDP server")
+    # One protocol instance will be created to serve all client requests
     listen = loop.create_datagram_endpoint(
-        EchoServerClientProtocol, local_addr=('127.0.0.1', 9999))
+        EchoServerProtocol, local_addr=('127.0.0.1', 9999))
     transport, protocol = loop.run_until_complete(listen)
 
     try: