devxlogo

Socket Buffer Size

Socket Buffer Size

Question:
How do I set the socket input and output buffer sizes in Java?

Answer:
You cannot set the socket input and output buffer sizes in Java versions prior to 1.2. To do so requires writing native code. You just have to live with whatever the system default values are.Starting with Java 1.2, java.net.Socket has acquired four new methods:

  • void setSendBufferSize(int size)
  • int getSendBufferSize()
  • void setReceiveBufferSize(int size)
  • int getReceiveBufferSize()

You can now use these to set and fetch the socket send and receive buffer sizes. When setting the buffer sizes, it helps to remember that the value is only a hint to the underlying system TCP/IP code as to what size should be allocated. The underlying system will not necessarily allocate exactly what you request.

devx-admin

Share the Post: