1 2 3 4 5 6 7 8 9 10 11 12 13 14
#!/usr/bin/python import socket UDP_IP = "" UDP_PORT = 5000 sock = socket.socket(socket.AF_INET, # Internet socket.SOCK_DGRAM) # UDP sock.bind((UDP_IP, UDP_PORT)) while True: data, addr = sock.recvfrom(1024) # buffer size is 1024 bytes print "received message:", data