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

Skip to content

Commit 0bfa963

Browse files
committed
merged from 3.2
Issue #6005: Examples in the socket library documentation use sendall, where relevant, instead send method.
2 parents 4a2e1a0 + 6e13f13 commit 0bfa963

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
@@ -981,7 +981,8 @@ correspond to Unix system calls applicable to sockets.
981981
optional *flags* argument has the same meaning as for :meth:`recv` above.
982982
Returns the number of bytes sent. Applications are responsible for checking that
983983
all data has been sent; if only some of the data was transmitted, the
984-
application needs to attempt delivery of the remaining data.
984+
application needs to attempt delivery of the remaining data. For further
985+
information on this topic, consult the :ref:`socket-howto`.
985986

986987

987988
.. method:: socket.sendall(bytes[, flags])
@@ -1169,8 +1170,8 @@ using it. Note that a server must perform the sequence :func:`socket`,
11691170
:meth:`~socket.bind`, :meth:`~socket.listen`, :meth:`~socket.accept` (possibly
11701171
repeating the :meth:`~socket.accept` to service more than one client), while a
11711172
client only needs the sequence :func:`socket`, :meth:`~socket.connect`. Also
1172-
note that the server does not :meth:`~socket.send`/:meth:`~socket.recv` on the
1173-
socket it is listening on but on the new socket returned by
1173+
note that the server does not :meth:`~socket.sendall`/:meth:`~socket.recv` on
1174+
the socket it is listening on but on the new socket returned by
11741175
:meth:`~socket.accept`.
11751176

11761177
The first two examples support IPv4 only. ::
@@ -1188,7 +1189,7 @@ The first two examples support IPv4 only. ::
11881189
while True:
11891190
data = conn.recv(1024)
11901191
if not data: break
1191-
conn.send(data)
1192+
conn.sendall(data)
11921193
conn.close()
11931194

11941195
::
@@ -1200,7 +1201,7 @@ The first two examples support IPv4 only. ::
12001201
PORT = 50007 # The same port as used by the server
12011202
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
12021203
s.connect((HOST, PORT))
1203-
s.send(b'Hello, world')
1204+
s.sendall(b'Hello, world')
12041205
data = s.recv(1024)
12051206
s.close()
12061207
print('Received', repr(data))
@@ -1272,7 +1273,7 @@ sends traffic to the first one connected successfully. ::
12721273
if s is None:
12731274
print('could not open socket')
12741275
sys.exit(1)
1275-
s.send(b'Hello, world')
1276+
s.sendall(b'Hello, world')
12761277
data = s.recv(1024)
12771278
s.close()
12781279
print('Received', repr(data))

Doc/library/socketserver.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ This is the server side::
365365
print("{} wrote:".format(self.client_address[0]))
366366
print(self.data)
367367
# just send back the same data, but upper-cased
368-
self.request.send(self.data.upper())
368+
self.request.sendall(self.data.upper())
369369

370370
if __name__ == "__main__":
371371
HOST, PORT = "localhost", 9999
@@ -395,7 +395,7 @@ objects that simplify communication by providing the standard file interface)::
395395
The difference is that the ``readline()`` call in the second handler will call
396396
``recv()`` multiple times until it encounters a newline character, while the
397397
single ``recv()`` call in the first handler will just return what has been sent
398-
from the client in one ``send()`` call.
398+
from the client in one ``sendall()`` call.
399399

400400

401401
This is the client side::
@@ -412,7 +412,7 @@ This is the client side::
412412
try:
413413
# Connect to server and send data
414414
sock.connect((HOST, PORT))
415-
sock.send(bytes(data + "\n", "utf-8"))
415+
sock.sendall(bytes(data + "\n", "utf-8"))
416416

417417
# Receive data from the server and shut down
418418
received = str(sock.recv(1024), "utf-8")
@@ -510,7 +510,7 @@ An example for the :class:`ThreadingMixIn` class::
510510
data = str(self.request.recv(1024), 'ascii')
511511
cur_thread = threading.current_thread()
512512
response = bytes("{}: {}".format(cur_thread.name, data), 'ascii')
513-
self.request.send(response)
513+
self.request.sendall(response)
514514

515515
class ThreadedTCPServer(socketserver.ThreadingMixIn, socketserver.TCPServer):
516516
pass
@@ -519,7 +519,7 @@ An example for the :class:`ThreadingMixIn` class::
519519
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
520520
sock.connect((ip, port))
521521
try:
522-
sock.send(bytes(message, 'ascii'))
522+
sock.sendall(bytes(message, 'ascii'))
523523
response = str(sock.recv(1024), 'ascii')
524524
print("Received: {}".format(response))
525525
finally:

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,9 @@ Library
484484
make sure two listeners can't bind to the same socket/pipe (or any existing
485485
socket/pipe).
486486

487+
- Issue #6005: Examples in the socket library documentation use sendall, where
488+
relevant, instead send method.
489+
487490
- Issue #10811: Fix recursive usage of cursors. Instead of crashing,
488491
raise a ProgrammingError now.
489492

0 commit comments

Comments
 (0)