Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Configuring sockets to use small packets in Java

I am processing time critical messages which are routed to me via a very slow network connection. I am connecting to the originating server (which I have no control over) with a Java TCP/IP Socket. The data is of varying length but is usually around 5000bytes and so ends up getting broken into multiple packets of roughly 1400 bytes.

Is there any way in my Java client-side code that I can control the size of the packets that are used to send me the data? I would like to experiment with explicitly using smaller packets sizes, for example 500 byte packets, which would decrease the time it takes for me to receive the first byte of the message at the (possible) cost of increased header overhead.


1 Answers

I don't think you can control this from the client if you can't control or change your server. I suspect the server is packing the data into a 1500 byte ethernet frame (see here for details) and trying to optimise its delivery of data to you.

This 1500 bytes is called the MTU. You could possibly play around with this at the OS layer, but I suspect that'll bring you nothing but grief.

like image 176
Brian Agnew Avatar answered May 23 '26 12:05

Brian Agnew



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!