I'm using Python and I have a problem with UDP Socket as a server. I send packets from a client but the data is too large to send in one packet (several MBytes) so I fragment the data in packets of 65K (IP fragments it in 1500 bytes packets (MTU) and reassambles them in the server). I see the packets in Wiresharks so there isn't a problem in the transmission.
The transimision code is :
while(end == False):
if total_length - count >= MTU:
length_send = self._socket.sendto(msgbuff[count:count + MTU],(IP,PORT))
else:
length_send = self._socket.sendto(msgbuff[count:],(IP,PORT))
count += length_send
if count == total_length:
end = True
The problem is in the recepction. I use a sync header to know where the datas begins (some fix bytes as 0xB451B451 for example). In some runs the server works well and find the sync header and it's able to recover all the packet.
However, in others runs the sockets only receives the last packets of the block data. For example : The block Data is 100K , the first packets is 65K and the second 35K. The sockets always returns the 35K packet.
The code of the server is:
while not synchronized_flag:
msg, __ = self._socket.recvfrom(MTU)
seq_sync = msg[0:length(SYNQ_HEADER)]
if seq_sync == SYNQ_HEADER:
synchronized_flag = True
total_length = getLength(msg)
bytes_read = 0
while bytes_read < total_length:
msg_aux, _ = self._socket.recvfrom(MTU)
msg.extend(msg_aux)
bytes_read += len(msg_aux)
Thanks for your support.
In addition I must say that I can't use TCP because I need the highest speed I'm able to get.