Bytearrays not sent consistently over socket

I’m trying to send 8000 bytes from the OpenMV to my PC using sockets with the wifi shield. However, the OpenMV is not sending the message consistently.

s = usocket.socket(usocket.AF_INET, usocket.SOCK_STREAM)
s.connect((HOST, PORT))

data = bytearray(os.urandom(8000)

On the PC side, I receive bytes from the socket until the length is 8000. As a test, I print out the lengths of the messages that the PC is receiving. Sometimes the OpenMV sends one message of 8000 bytes and the PC receives all 8000. Sometimes the OpenMV sends 5 messages of lengths 2800, 1400, 1400, 1400, 1000. Sometimes the OpenMV sends 5 messages of lengths 1400, 2800, 1400, 1400, 1000.

For my application, it would be great if the OpenMV is able to consistently send 8000 bytes at once. Or, at least I’d like the OpenMV to send predictable message sizes. The OpenMV uses the same wifi module as the Adafruit Feather M0, but I haven’t had this problem with the Feather. Please advise.

Just did another run, this time it sent the 8000 bytes in 3 messages of lengths 2400, 1400, 3800. Not sure what’s going on…

The max packet size is 1400 (MTU) it seems some packets are combined on the PC/router side, try blocking until you receive the whole 8000 bytes or send the packet in chunks of 1400 bytes.