MCPcopy
hub / github.com/dabeaz/python-cookbook / echo_client

Function echo_client

src/12/how_to_create_a_thread_pool/example2.py:5–17  ·  view source on GitHub ↗

Handle a client connection

(q)

Source from the content-addressed store, hash-verified

3from queue import Queue
4
5def echo_client(q):
6 '''
7 Handle a client connection
8 '''
9 sock, client_addr = q.get()
10 print('Got connection from', client_addr)
11 while True:
12 msg = sock.recv(65536)
13 if not msg:
14 break
15 sock.sendall(msg)
16 print('Client closed connection')
17 sock.close()
18
19def echo_server(addr, nworkers):
20 print('Echo server running at', addr)

Callers

nothing calls this directly

Calls 3

getMethod · 0.45
recvMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected