Showing posts with label UDP. Show all posts
Showing posts with label UDP. Show all posts

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

It speaks!

HydraRaptor just replied to ping, so that's PHY, MAC, ARP, IP and ICMP working.

Pinging 10.0.0.42 with 32 bytes of data:

Reply from 10.0.0.42: bytes=32 time=1ms TTL=128
Reply from 10.0.0.42: bytes=32 time<1ms TTL=128
Reply from 10.0.0.42: bytes=32 time<1ms TTL=128
Reply from 10.0.0.42: bytes=32 time<1ms TTL=128

Ping statistics for 10.0.0.42:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 0ms, Maximum = 1ms, Average = 0ms

UDP next.