8000 gh-112020: socketserver: Add an example for keeping the connection open by talcs · Pull Request #112054 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-112020: socketserver: Add an example for keeping the connection open #112054

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 8 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
updating readline example too
  • Loading branch information
talcs authored Feb 20, 2024
commit d92bebbb60811307113c89ce209dd74035712300
11 changes: 8 additions & 3 deletions Doc/library/socketserver.rst
Original file line number Diff line number Diff line change
Expand Up @@ -519,9 +519,14 @@ objects that simplify communication by providing the standard file interface)::
class MyTCPHandler(socketserver.StreamRequestHandler):

def handle(self):
# self.rfile is a file-like object created by the handler;
# we can now use e.g. readline() instead of raw recv() calls
self.data = self.rfile.readline().strip()
while True:
# self.rfile is a file-like object created by the handler;
# we can now use e.g. readline() instead of raw recv() calls
self.data = self.rfile.readline()
if not self.data:
# Client has hung up
break
self.data = self.data.strip()
print("{} wrote:".format(self.client_address[0]))
print(self.data)
# Likewise, self.wfile is a file-like object used to write back
Expand Down
0