views:

154

answers:

2

Hello everybody, I am trying to read UDP packages sent by an FPGA with my computer. They are sent to port 21844 and to the IP 192.168.1.2 (which is my computer's IP). I can see the package in wireshark, they have no errors. When I run however this little python script, then only a very very small fraction of all packages are received by it, also depending if wireshark is running or not.

import socket
import sys


HOST, PORT = "192.168.1.2", 21844
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.bind((HOST,PORT)) 
received ,address= sock.recvfrom(2048)
print address

I use windows 7 with Norton Internet Security, where I allow all traffic in the firewall for the FPGA IP and also for python. The same program on a Windows XP computer does not receive anything either...

Thanks for any help!

+2  A: 

The TCP/IP stack of your OS doesn't hold those packets for you for eternity. Your script looks like something that very much depends on when it is run. Try to recvfrom in a loop, and run the script in the background. Then, start sending packets from your FPGA.

For extra convenience, explore the SocketServer module from Python's stdlib.

Eli Bendersky
Thanks for your answer, Eli! I actually also tried to use it in a loop, like: while 1: received ,address= sock.recvfrom(2048) print received, addressAlso in this case only a very small amount of the packages was captured...
Michael
A: 

Ok, I found the problem: The UDP checksum in the FPGA was computed wrongly. Wireshark shows every package, but by default it does not check if the checksum is correct. When I set the checksum to 0x0000, then the packages arrive in python! Thanks for your help again!

Michael