Monday, 23 April 2007

It speaks, but my PC has its fingers in its ears

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 = ""
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)

# Send a get status command
cmd = "\x12\x34\x56\x78\x00"
print "Sending message ....."

# Receive the reply
data,addr = recvSock.recvfrom(buf)
if data:
print " Received message '", data, "'"
print "Read failed"

# Close sockets
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
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.

1 comment:

  1. I fixed it! The receive socket ip address should be the empty string to mean INADDR_ANY, not "localhost" as that means receive from the PC.