UDP Connectionless Example : UDP Client « Network « Python Tutorial






import socket, sys, struct, time

hostname = 'time.nist.gov'
port = 37

host = socket.gethostbyname(hostname)

s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.sendto('', (host, port))

print "Looking for replies; press Ctrl-C to stop."

buf = s.recvfrom(2048)[0]

if len(buf) != 4:
    print "Wrong-sized reply %d: %s" % (len(buf), buf)
    sys.exit(1)

secs = struct.unpack("!I", buf)[0]
secs -= 2208988800
print time.ctime(int(secs))








21.13.UDP Client
21.13.1.UDP Timestamp Client (tsUclnt.py)
21.13.2.A client that will send packets to a server and receive packets from a server.
21.13.3.UDP Example
21.13.4.UDP client example
21.13.5.UDP Connectionless Example