Your Options With Sockets

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 java.net.Socket 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 java.io.InterruptedIOException 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 java.net.Socket 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 java.net.Socket 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 java.net.Socket 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 java.net.Socket 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:
Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular

XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several

data fivetran pricing

Fivetran Pricing Explained

One of the biggest trends of the 21st century is the massive surge in analytics. Analytics is the process of utilizing data to drive future decision-making. With so much of