Search code examples
androidudpdatagram

Size of custom datagram packet


I am working on a client-server file transfer android application to transfer video files using Wi-Fi. I have created a custom datagram packet which includes a byte[] for data, an int for the sequence numbers and a boolean for the acknowledgements.

I am using 500 bytes for the data at the client side and 590 bytes (590 calculated by hit and trial) at the server end while receiving, which is working fine.

Also, I have noticed that if I use 1400 bytes at the client side and 1490 at the server size, the file received is corrupted and does not play.

1) How should i calculate the exact size of receiving packet at the server end?

2) Why is the received file corrupted when I use 1400 bytes? (MTU is 1500)


Solution

  • The generally accepted safe limit for UDP datagram payload size is 534 bytes. This is derived somehow from the magic number of 576 which is the largest IP packet size that Internet routers are not permitted to fragment. Seems to me it should be 576-28=548 but maybe you need to allow more room for IP options.