简体   繁体   中英

Is there a way to find out in Java the maximum allowed underlying read TCP socket buffer configured in the OS?

I know you can call socket.setReceiveBufferSize(int) and socket.getReceiveBufferSize() .

You can do something like:

socket.setReceiveBufferSize(Integer.MAX_VALUE);

int after = socket.getReceiveBufferSize();

if (after != Integer.MAX_VALUE) System.out.println("That did not work!");

Based on that, I would like to write an algo to guess correctly the max underlying read socket buffer size configured at the OS level. How can I do that? Binary search? Or is there a much simpler way?

The after should be the maximum size assuming it didn't actually give you the size you wanted. Making the buffer too big might actually hurt performance (as well as waste memory)

I would try to set it to the maximum you would want it to be, eg a few MB, and if that is too might it should be the maximum.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM