I almost got UDP working this evening. I wrote a simple
Python test script to send a "get status" command to HydraRaptor. Here it is :-
from socket import *
# Set the socket parameters
hydra = "10.0.0.42"
inPort = 21000
inAddr = (hydra,inPort)
outPort = 21001
outAddr = ("localhost",outPort)
buf = 1024
# Create sockets
sendSock = socket(AF_INET,SOCK_DGRAM)
recvSock = socket(AF_INET,SOCK_DGRAM)
recvSock.bind(outAddr)
recvSock.settimeout(2.0)
# Send a get status command
cmd = "\x12\x34\x56\x78\x00"
if(sendSock.sendto(cmd,inAddr)):
print "Sending message ....."
# Receive the reply
try:
data,addr = recvSock.recvfrom(buf)
if data:
print " Received message '", data, "'"
except:
print "Read failed"
# Close sockets
recvSock.close()
sendSock.close()
HydraRaptor replies with its x,y,z coordinates and the number of steps remaining. The reply packet arrives at my PC which then sends an ICMP destination unreachable (port unreachable) message back. I have no idea why. netstat -ad shows :
UDP shuttle:21001 *:* 2412
[Pythonwin.exe]
Which looks to me to show that the port is being listened to. I have tried turning my firewall off but that made no difference. I am sure the problem is at the PC end because
Ethereal shows me that the packets are well formed. I have had enough for this evening. Any Python socket experts out there? I have never done sockets in Python before.