I use these 2 pieces of code from http://wiki.python.org/moin/UdpCommunication
Server:
import socket UDP_IP="127.0.0.1" UDP_PORT=5005 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,"from", addr
Customer:
import socket UDP_IP="127.0.0.1" UDP_PORT=5005 MESSAGE="Hello, World!" print "UDP target IP:", UDP_IP print "UDP target port:", UDP_PORT print "message:", MESSAGE sock = socket.socket( socket.AF_INET,
On the server, I changed the last line:
print "received message:", data,"from", addr
so that it prints the address from which the message was sent. On my macbook, the port seems to be a random number between 40,000 or 65,000 (I'm just sure it seems random).
Any idea what this could be?
source share