Handle a client connection
(q)
| 3 | from queue import Queue |
| 4 | |
| 5 | def 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 | |
| 19 | def echo_server(addr, nworkers): |
| 20 | print('Echo server running at', addr) |