https://github.com/python/cpython/commit/fe0f544f33adf6128400f103187ba9f3cee13549 commit: fe0f544f33adf6128400f103187ba9f3cee13549 branch: 3.11 author: Miss Islington (bot) <[email protected]> committer: hauntsaninja <[email protected]> date: 2024-02-01T00:50:58Z summary:
[3.11] gh-111112: Avoid potential confusion in TCP server example. (GH-111113) (#114832) gh-111112: Avoid potential confusion in TCP server example. (GH-111113) Improve misleading TCP server docs and example. socket.recv(), as documented by the Python reference documentation, returns at most `bufsize` bytes, and the underlying TCP protocol means there is no guaranteed correspondence between what is sent by the client and what is received by the server. This conflation could mislead readers into thinking that TCP is datagram-based or has similar semantics, which will likely appear to work for simple cases, but introduce difficult to reproduce bugs. (cherry picked from commit a79a27242f75fc33416d4d135a4a542898d140e5) Co-authored-by: Aidan Holm <[email protected]> files: M Doc/library/socketserver.rst diff --git a/Doc/library/socketserver.rst b/Doc/library/socketserver.rst index 7540375b8d1f50..5e92332c5f195c 100644 --- a/Doc/library/socketserver.rst +++ b/Doc/library/socketserver.rst @@ -488,7 +488,7 @@ This is the server side:: def handle(self): # self.request is the TCP socket connected to the client self.data = self.request.recv(1024).strip() - print("{} wrote:".format(self.client_address[0])) + print("Received from {}:".format(self.client_address[0])) print(self.data) # just send back the same data, but upper-cased self.request.sendall(self.data.upper()) @@ -519,8 +519,9 @@ 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 ``sendall()`` call. +single ``recv()`` call in the first handler will just return what has been +received so far from the client's ``sendall()`` call (typically all of it, but +this is not guaranteed by the TCP protocol). This is the client side:: _______________________________________________ Python-checkins mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3/lists/python-checkins.python.org/ Member address: [email protected]
