MCPcopy Create free account
hub / github.com/dabeaz/python-cookbook / time_server

Function time_server

src/11/creating_a_udp_server/timeserv2.py:4–11  ·  view source on GitHub ↗
(address)

Source from the content-addressed store, hash-verified

2import time
3
4def time_server(address):
5 sock = socket(AF_INET, SOCK_DGRAM)
6 sock.bind(address)
7 while True:
8 msg, addr = sock.recvfrom(8192)
9 print('Got message from', addr)
10 resp = time.ctime()
11 sock.sendto(resp.encode('ascii'), addr)
12
13if __name__ == '__main__':
14 time_server(('', 20000))

Callers 1

timeserv2.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected