Fix Issue #6005: Examples in the socket library documentation use sendall,

where relevant, instead send method.
This commit is contained in:
Senthil Kumaran 2012-02-09 17:54:17 +08:00
parent b2c9e9ad91
commit 6e13f130a9
4 changed files with 17 additions and 11 deletions

View file

@ -353,7 +353,7 @@ This is the server side::
print("{} wrote:".format(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
@ -383,7 +383,7 @@ objects that simplify communication by providing the standard file interface)::
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::
@ -400,7 +400,7 @@ This is the client side::
try:
# Connect to server and send data
sock.connect((HOST, PORT))
sock.send(bytes(data + "\n", "utf-8"))
sock.sendall(bytes(data + "\n", "utf-8"))
# Receive data from the server and shut down
received = str(sock.recv(1024), "utf-8")
@ -498,7 +498,7 @@ An example for the :class:`ThreadingMixIn` class::
data = str(self.request.recv(1024), 'ascii')
cur_thread = threading.current_thread()
response = bytes("{}: {}".format(cur_thread.name, data), 'ascii')
self.request.send(response)
self.request.sendall(response)
class ThreadedTCPServer(socketserver.ThreadingMixIn, socketserver.TCPServer):
pass
@ -507,7 +507,7 @@ An example for the :class:`ThreadingMixIn` class::
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((ip, port))
try:
sock.send(bytes(message, 'ascii'))
sock.sendall(bytes(message, 'ascii'))
response = str(sock.recv(1024), 'ascii')
print("Received: {}".format(response))
finally: