cpython: d34beaaf7060 (original) (raw)

--- a/Doc/library/socketserver.rst +++ b/Doc/library/socketserver.rst @@ -348,7 +348,7 @@ This is the server side:: def handle(self): # self.request is the TCP socket connected to the client self.data = self.request.recv(1024).strip()

@@ -372,7 +372,7 @@ objects that simplify communication by p # self.rfile is a file-like object created by the handler; # we can now use e.g. readline() instead of raw recv() calls self.data = self.rfile.readline().strip()

@@ -395,16 +395,18 @@ This is the client side:: # Create a socket (SOCK_STREAM means a TCP socket) sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

The output of the example should look something like this: @@ -421,10 +423,10 @@ Client:: $ python TCPClient.py hello world with TCP Sent: hello world with TCP

:class:socketserver.UDPServer Example @@ -445,7 +447,7 @@ This is the server side:: def handle(self): data = self.request[0].strip() socket = self.request[1]

@@ -467,11 +469,11 @@ This is the client side:: # As you can see, there is no connect() call; UDP has no connections. # Instead, data is directly sent to the recipient via sendto().

The output of the example should look exactly like for the TCP server example. @@ -491,9 +493,9 @@ An example for the :class:`ThreadingMixI class ThreadedTCPRequestHandler(socketserver.BaseRequestHandler): def handle(self):

class ThreadedTCPServer(socketserver.ThreadingMixIn, socketserver.TCPServer): @@ -502,10 +504,12 @@ An example for the :class:`ThreadingMixI def client(ip, port, message): sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.connect((ip, port))

if name == "main": # Port 0 means to select an arbitrary unused port @@ -518,13 +522,13 @@ An example for the :class:`ThreadingMixI # more thread for each request server_thread = threading.Thread(target=server.serve_forever) # Exit the server thread when the main thread terminates

server.shutdown() @@ -533,9 +537,9 @@ The output of the example should look so $ python ThreadedTCPServer.py Server loop running in thread: Thread-1

The :class:ForkingMixIn class is used in the same way, except that the server

--- a/Misc/NEWS +++ b/Misc/NEWS @@ -190,6 +190,12 @@ Extension Modules