Your Options With Sockets

JDK 1.1 offers enhanced control over a socket’s behavior through some socket options. These options are:

SO_TIMEOUT, which you can access through accessor methods:

 	public synchronized int getSoTimeout() throws SocketException	public synchronized void setSoTimeout(int timeout) throwsSocketException

of class.

The specified timeout is in milliseconds. With this option set to a non-zero timeout, a read() call on the InputStream associated with this Socket will block for only the specified amount of time. If the timeout expires, a is raised, but the Socket remains valid. In order to have effect, the option must be enabled prior to entering. The timeout must be greater than 0, because a timeout of zero is interpreted as an infinite timeout.

SO_LINGER, accessed through accessor methods:

 	public int getSoLinger() throws SocketException	public void setSoLinger(boolean on, int linger) throwsSocketException

of class.

With this option, you can indicate whether you want the socket to linger on after its close() method is called in order to send its queued data to its peer. The linger variable of the setter method tells the socket how long(seconds) it should linger on after the invocation of its close() method in order to try to send queued data before it closes itself. The getter returns to you the length of time (seconds) the socket would linger on after its close() method is called. A return of -1 implies that the linger option is disabled.

TCP_NODELAY, accessed through accessor methods:

 	public boolean getTcpNoDelay() throws SocketException	public void setTcpNoDelay(boolean on) throws SocketException

of class.

This one concerns Nagle’s algorithm, which stops a machine on a network flooding an Internet by forcing the system to throttle back the output dependent on the replies from the far end. When a broadband link between the two points exist the TCP connection increases its bandwidth, but will slow down if things get congested.

As of Java 2 (a.k.a. Java 1.2), two more options have been added to sockets:

SO_RCVBUF, can be accessed through accessor methods:

 public void setReceiveBufferSize(int size) throws SocketExceptionpublic int getReceiveBufferSize()throws SocketException

of class.

This option indicates the size of the underlying network I/O buffer for input on the socket.

SO_SNDBUF, can be accessed through accessor methods:

 public int getSendBufferSize() throws SocketExceptionpublic void setSendBufferSize(int size) throws SocketException

of class.

This option indicates the size of the underlying network I/O buffer for output on the socket.

For both SO_SNDBUF and SO_RCVBUF, increasing the buffer size may increase the performance. Reducing it may help reduce backlog of in-bound data. For UDP packets, these options set the maximum size of a packet that may be sent on the socket.

Share the Post:
Share on facebook
Share on twitter
Share on linkedin


The Latest

your company's audio

4 Areas of Your Company Where Your Audio Really Matters

Your company probably relies on audio more than you realize. Whether you’re creating a spoken text message to a colleague or giving a speech, you want your audio to shine. Otherwise, you could cause avoidable friction points and potentially hurt your brand reputation. For example, let’s say you create a

chrome os developer mode

How to Turn on Chrome OS Developer Mode

Google’s Chrome OS is a popular operating system that is widely used on Chromebooks and other devices. While it is designed to be simple and user-friendly, there are times when users may want to access additional features and functionality. One way to do this is by turning on Chrome OS

homes in the real estate industry

Exploring the Latest Tech Trends Impacting the Real Estate Industry

The real estate industry is changing thanks to the newest technological advancements. These new developments — from blockchain and AI to virtual reality and 3D printing — are poised to change how we buy and sell homes. Real estate brokers, buyers, sellers, wholesale real estate professionals, fix and flippers, and beyond may