MCPcopy Create free account
hub / github.com/dabeaz-course/python-mastery / tcp_server

Function tcp_server

Solutions/8_6/asyncserver.py:55–62  ·  view source on GitHub ↗
(address, handler)

Source from the content-addressed store, hash-verified

53 return getattr(self.sock, name)
54
55async def tcp_server(address, handler):
56 sock = GenSocket(socket(AF_INET, SOCK_STREAM))
57 sock.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)
58 sock.bind(address)
59 sock.listen(5)
60 while True:
61 client, addr = await sock.accept()
62 tasks.append(handler(client, addr))
63
64async def echo_handler(client, address):
65 print('Connection from', address)

Callers 1

asyncserver.pyFile · 0.70

Calls 3

acceptMethod · 0.95
appendMethod · 0.80
GenSocketClass · 0.70

Tested by

no test coverage detected