Set up a server that will receive packets from a client and send packets to a client : UDP Server « Network « Python Tutorial






import socket

HOST = "127.0.0.1"
PORT = 5000

mySocket = socket.socket( socket.AF_INET, socket.SOCK_DGRAM )

mySocket.bind( ( HOST, PORT ) )

while 1:
   packet, address = mySocket.recvfrom( 1024 )

   print "From host:", address[ 0 ]
   print "Host port:", address[ 1 ]
   print "Length:", len( packet )
   print "\t" + packet

   mySocket.sendto( packet, address )
   print "Packet sent\n"

mySocket.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