UDP Timestamp Server : UDP Server « Network « Python Tutorial






from socket import *
from time import ctime

HOST = ''
PORT = 21567
BUFSIZ = 1024
ADDR = (HOST, PORT)

udpSerSock = socket(AF_INET, SOCK_DGRAM)
udpSerSock.bind(ADDR)

while True:
    print 'waiting for message...'
    data, addr = udpSerSock.recvfrom(BUFSIZ)
    udpSerSock.sendto('[%s] %s' % (
        ctime(), data), addr)
    print '...received from and returned to:', addr

udpSerSock.close()








21.14.UDP Server
21.14.1.UDP Timestamp Server
21.14.2.Set up a server that will receive packets from a client and send packets to a client
21.14.3.UDP Echo Server