A client that will send packets to a server and receive packets from a server. : UDP Client « Network « Python Tutorial






import socket

HOST = "127.0.0.1"
PORT = 5000

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

while 1:
   packet = "Packet"
   mySocket.sendto( packet, ( HOST, PORT ) )
   packet, address = mySocket.recvfrom( 1024 )
   print "Packet received:"
   print "From host:", address[ 0 ]
   print "Host port:", address[ 1 ]
   print "Length:", len( packet )
   print "Containing:"
   print "\t" + packet + "\n"

mySocket.close()








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