Index: Doc/library/socket.rst =================================================================== --- Doc/library/socket.rst (revision 83828) +++ Doc/library/socket.rst (working copy) @@ -785,8 +785,8 @@ :meth:`~socket.bind`, :meth:`~socket.listen`, :meth:`~socket.accept` (possibly repeating the :meth:`~socket.accept` to service more than one client), while a client only needs the sequence :func:`socket`, :meth:`~socket.connect`. Also -note that the server does not :meth:`~socket.send`/:meth:`~socket.recv` on the -socket it is listening on but on the new socket returned by +note that the server does not :meth:`~socket.sendall`/:meth:`~socket.recv` on +the socket it is listening on but on the new socket returned by :meth:`~socket.accept`. The first two examples support IPv4 only. :: @@ -804,7 +804,7 @@ while True: data = conn.recv(1024) if not data: break - conn.send(data) + conn.sendall(data) conn.close() :: @@ -816,7 +816,7 @@ PORT = 50007 # The same port as used by the server s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((HOST, PORT)) - s.send(b'Hello, world') + s.sendall(b'Hello, world') data = s.recv(1024) s.close() print('Received', repr(data)) @@ -859,7 +859,7 @@ while True: data = conn.recv(1024) if not data: break - conn.send(data) + conn.sendall(data) conn.close() :: @@ -888,7 +888,7 @@ if s is None: print('could not open socket') sys.exit(1) - s.send(b'Hello, world') + s.sendall(b'Hello, world') data = s.recv(1024) s.close() print('Received', repr(data)) Index: Doc/library/socketserver.rst =================================================================== --- Doc/library/socketserver.rst (revision 83828) +++ Doc/library/socketserver.rst (working copy) @@ -347,7 +347,7 @@ print("%s wrote:" % self.client_address[0]) print(self.data) # just send back the same data, but upper-cased - self.request.send(self.data.upper()) + self.request.sendall(self.data.upper()) if __name__ == "__main__": HOST, PORT = "localhost", 9999 @@ -377,7 +377,7 @@ The difference is that the ``readline()`` call in the second handler will call ``recv()`` multiple times until it encounters a newline character, while the single ``recv()`` call in the first handler will just return what has been sent -from the client in one ``send()`` call. +from the client in one ``sendall()`` call. This is the client side:: @@ -393,7 +393,7 @@ # Connect to server and send data sock.connect((HOST, PORT)) - sock.send(bytes(data + "\n","utf8")) + sock.sendall(bytes(data + "\n","utf8")) # Receive data from the server and shut down received = sock.recv(1024) @@ -490,7 +490,7 @@ data = self.request.recv(1024) cur_thread = threading.current_thread() response = bytes("%s: %s" % (cur_thread.getName(), data),'ascii') - self.request.send(response) + self.request.sendall(response) class ThreadedTCPServer(socketserver.ThreadingMixIn, socketserver.TCPServer): pass @@ -498,7 +498,7 @@ def client(ip, port, message): sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.connect((ip, port)) - sock.send(message) + sock.sendall(message) response = sock.recv(1024) print("Received: %s" % response) sock.close()