bahar_p
bahar_p

Reputation: 441

Android - send DatagramSocket max buffer size

I have an app that sends data over UDP. I'm trying to find out what is the max/optimal send buffer size. I have succeedded sending a 2k package, but bigger packets was a problem. I tried using getSendBufferSize to see what is the send buffer size. It returned 110592 bytes. When I try to send anything close to it, I dont get an error, but the data dosent get to the server.

How do I know what is the "allowed" send buffer size?

Thanks.

Upvotes: 3

Views: 3552

Answers (2)

Amos
Amos

Reputation: 2670

I've also encountered this error, it should be 65535 - 28 = 65507 bytes, for DatagramPacket send method's parameter "buffer" size.

Upvotes: 1

DatagramPacket is just a wrapper on a UDP based socket, so the usual UDP rules apply.

64 kilobytes is the theoretical maximum size of a complete IP datagram, but only 576 bytes are guaranteed to be routed. On any given network path, the link with the smallest Maximum Transmit Unit will determine the actual limit. (1500 bytes, less headers is the common maximum, but it is impossible to predict how many headers there will be so its safest to limit messages to around 1400 bytes.)

Reference : Java DatagramPacket (UDP) maximum send/recv buffer size

Upvotes: 2

Related Questions