Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6e13f13

Browse files
committed
Fix Issue #6005: Examples in the socket library documentation use sendall,
where relevant, instead send method.
1 parent b2c9e9a commit 6e13f13

4 files changed

Lines changed: 17 additions & 11 deletions

File tree

Doc/howto/sockets.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
.. _socket-howto:
2+
13
****************************
24
Socket Programming HOWTO
35
****************************

Doc/library/socket.rst

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,8 @@ correspond to Unix system calls applicable to sockets.
731731
optional *flags* argument has the same meaning as for :meth:`recv` above.
732732
Returns the number of bytes sent. Applications are responsible for checking that
733733
all data has been sent; if only some of the data was transmitted, the
734-
application needs to attempt delivery of the remaining data.
734+
application needs to attempt delivery of the remaining data. For further
735+
information on this topic, consult the :ref:`socket-howto`.
735736

736737

737738
.. method:: socket.sendall(bytes[, flags])
@@ -886,8 +887,8 @@ using it. Note that a server must perform the sequence :func:`socket`,
886887
:meth:`~socket.bind`, :meth:`~socket.listen`, :meth:`~socket.accept` (possibly
887888
repeating the :meth:`~socket.accept` to service more than one client), while a
888889
client only needs the sequence :func:`socket`, :meth:`~socket.connect`. Also
889-
note that the server does not :meth:`~socket.send`/:meth:`~socket.recv` on the
890-
socket it is listening on but on the new socket returned by
890+
note that the server does not :meth:`~socket.sendall`/:meth:`~socket.recv` on
891+
the socket it is listening on but on the new socket returned by
891892
:meth:`~socket.accept`.
892893

893894
The first two examples support IPv4 only. ::
@@ -905,7 +906,7 @@ The first two examples support IPv4 only. ::
905906
while True:
906907
data = conn.recv(1024)
907908
if not data: break
908-
conn.send(data)
909+
conn.sendall(data)
909910
conn.close()
910911

911912
::
@@ -917,7 +918,7 @@ The first two examples support IPv4 only. ::
917918
PORT = 50007 # The same port as used by the server
918919
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
919920
s.connect((HOST, PORT))
920-
s.send(b'Hello, world')
921+
s.sendall(b'Hello, world')
921922
data = s.recv(1024)
922923
s.close()
923924
print('Received', repr(data))
@@ -989,7 +990,7 @@ sends traffic to the first one connected successfully. ::
989990
if s is None:
990991
print('could not open socket')
991992
sys.exit(1)
992-
s.send(b'Hello, world')
993+
s.sendall(b'Hello, world')
993994
data = s.recv(1024)
994995
s.close()
995996
print('Received', repr(data))

Doc/library/socketserver.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ This is the server side::
353353
print("{} wrote:".format(self.client_address[0]))
354354
print(self.data)
355355
# just send back the same data, but upper-cased
356-
self.request.send(self.data.upper())
356+
self.request.sendall(self.data.upper())
357357

358358
if __name__ == "__main__":
359359
HOST, PORT = "localhost", 9999
@@ -383,7 +383,7 @@ objects that simplify communication by providing the standard file interface)::
383383
The difference is that the ``readline()`` call in the second handler will call
384384
``recv()`` multiple times until it encounters a newline character, while the
385385
single ``recv()`` call in the first handler will just return what has been sent
386-
from the client in one ``send()`` call.
386+
from the client in one ``sendall()`` call.
387387

388388

389389
This is the client side::
@@ -400,7 +400,7 @@ This is the client side::
400400
try:
401401
# Connect to server and send data
402402
sock.connect((HOST, PORT))
403-
sock.send(bytes(data + "\n", "utf-8"))
403+
sock.sendall(bytes(data + "\n", "utf-8"))
404404

405405
# Receive data from the server and shut down
406406
received = str(sock.recv(1024), "utf-8")
@@ -498,7 +498,7 @@ An example for the :class:`ThreadingMixIn` class::
498498
data = str(self.request.recv(1024), 'ascii')
499499
cur_thread = threading.current_thread()
500500
response = bytes("{}: {}".format(cur_thread.name, data), 'ascii')
501-
self.request.send(response)
501+
self.request.sendall(response)
502502

503503
class ThreadedTCPServer(socketserver.ThreadingMixIn, socketserver.TCPServer):
504504
pass
@@ -507,7 +507,7 @@ An example for the :class:`ThreadingMixIn` class::
507507
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
508508
sock.connect((ip, port))
509509
try:
510-
sock.send(bytes(message, 'ascii'))
510+
sock.sendall(bytes(message, 'ascii'))
511511
response = str(sock.recv(1024), 'ascii')
512512
print("Received: {}".format(response))
513513
finally:

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,9 @@ Core and Builtins
113113
Library
114114
-------
115115

116+
- Issue #6005: Examples in the socket library documentation use sendall, where
117+
relevant, instead send method.
118+
116119
- Issue #10811: Fix recursive usage of cursors. Instead of crashing,
117120
raise a ProgrammingError now.
118121

0 commit comments

Comments
 (0)