I'm using python socket to receive UDP packets sent by FPGA with a self-defined frame counter to indicate packet loss. My problem is the received data have 4 packets lost every 65536 packets received. Does windows socket has a 65536 packet limit? I'm not able to embed picture in my post. I will type the running result below:
start: 395070354
end: 395344794
Number of packets: 274441
Missing 4 packet from: 395115893 to: 395115898 distance from start: 45539
Missing 4 packet from: 395181429 to: 395181434 distance from start: 45539
Missing 4 packet from: 395246965 to: 395246970 distance from start: 45539
Missing 4 packet from: 395312501 to: 395312506 distance from start: 45539
Number of missing packets: 16
As you can see from the result, it's quite regular. 395181434-395115898=65536. 4 packets are lost every 65536 packets.
I've tried slow the transmitting speed. I assume it maybe the buffer size problem. I used the setsockopt function to change the RECVBUF size, but it's not working.
import socket
import time
import threading
def receive():
global data
while not kill.is_set():
data.append(fpga.recvfrom(512)[0])
fpga = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
fpga.bind(('192.168.253.8', 34))
miss=0
data=[]
kill=threading.Event()
p=threading.Thread(target=receive)
p.start()
time.sleep(10)
kill.set()
count=len(data)
start=int.from_bytes(data[0][0:4], byteorder='big')
end=int.from_bytes(data[count-1][0:4], byteorder='big')
print("start: ",start)
print("end: ",end)
print("Number of packets: ",end-start+1)
for i in range(0,count-1):
current=int.from_bytes(data[i][0:4], byteorder='big')
next=int.from_bytes(data[i+1][0:4], byteorder='big')
if next < current:
print("out of order detected!!!")
break
step=next-current
miss=miss+step-1
if step > 1:
print("Missing ",step-1," packet form: ",current," to: ",next,"distance form start: ",current-start)
print("Number of missing packets: ",miss)
range(0,count-1)will havecount-1items. So I wonder if your are handling the last item. - Klaus D.currentandnextvariables). also the "missing packets" are in the middle, not just the "last" item. - Sam Mason