summaryrefslogtreecommitdiffstats
path: root/Doc
diff options
context:
space:
mode:
authorSenthil Kumaran <senthil@uthcode.com>2012-02-09 09:55:56 (GMT)
committerSenthil Kumaran <senthil@uthcode.com>2012-02-09 09:55:56 (GMT)
commit0bfa963fbb45602923b858d00a44e788a4a42ad5 (patch)
tree9006f66fbabc3c4834e99df8098bf448520978e0 /Doc
parent4a2e1a0da7f1f16ee6a9ce75fdd60b4d30cb37d1 (diff)
parent6e13f130a9bde00db9fc17934987ed36da251aa7 (diff)
downloadcpython-0bfa963fbb45602923b858d00a44e788a4a42ad5.zip
cpython-0bfa963fbb45602923b858d00a44e788a4a42ad5.tar.gz
cpython-0bfa963fbb45602923b858d00a44e788a4a42ad5.tar.bz2
merged from 3.2
Issue #6005: Examples in the socket library documentation use sendall, where relevant, instead send method.
Diffstat (limited to 'Doc')
-rw-r--r--Doc/howto/sockets.rst2
-rw-r--r--Doc/library/socket.rst13
-rw-r--r--Doc/library/socketserver.rst10
3 files changed, 14 insertions, 11 deletions
diff --git a/Doc/howto/sockets.rst b/Doc/howto/sockets.rst
index 8ee334a..d240008 100644
--- a/Doc/howto/sockets.rst
+++ b/Doc/howto/sockets.rst
@@ -1,3 +1,5 @@
+.. _socket-howto:
+
****************************
Socket Programming HOWTO
****************************
diff --git a/Doc/library/socket.rst b/Doc/library/socket.rst
index 6b7728f..8cc5a7e 100644
--- a/Doc/library/socket.rst
+++ b/Doc/library/socket.rst
@@ -981,7 +981,8 @@ correspond to Unix system calls applicable to sockets.
optional *flags* argument has the same meaning as for :meth:`recv` above.
Returns the number of bytes sent. Applications are responsible for checking that
all data has been sent; if only some of the data was transmitted, the
- application needs to attempt delivery of the remaining data.
+ application needs to attempt delivery of the remaining data. For further
+ information on this topic, consult the :ref:`socket-howto`.
.. method:: socket.sendall(bytes[, flags])
@@ -1169,8 +1170,8 @@ using it. Note that a server must perform the sequence :func:`socket`,
: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. ::
@@ -1188,7 +1189,7 @@ The first two examples support IPv4 only. ::
while True:
data = conn.recv(1024)
if not data: break
- conn.send(data)
+ conn.sendall(data)
conn.close()
::
@@ -1200,7 +1201,7 @@ The first two examples support IPv4 only. ::
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))
@@ -1272,7 +1273,7 @@ sends traffic to the first one connected successfully. ::
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))
diff --git a/Doc/library/socketserver.rst b/Doc/library/socketserver.rst
index c7bc0d5..7dc0cc7 100644
--- a/Doc/library/socketserver.rst
+++ b/Doc/library/socketserver.rst
@@ -365,7 +365,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
@@ -395,7 +395,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::
@@ -412,7 +412,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")
@@ -510,7 +510,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
@@ -519,7 +519,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: