You are on page 1of 6

KeepAlive( ):

public boolean getKeepAlive( )


Functionality
The method returns a boolean value i.e., true or false if the setKeepAlive() method is enabled
or not.
Purpose
One problem with distributed applications is that if no data arrives over a long period of time, you need
to wonder why. So, getKeepAlive tells that whether program is alive or just have no data to send.

public void setKeepAlive(boolean on)


Functionality
Enable/disable SO_KEEPALIVE.
Purpose
The purpose of this function is to set that whether the program is still alive if in case no data is
arriving over a long period of time. Because the use need to know that either the program
crashed or it does not have any data to send.

Comparison:
KeepAlive() and ReceiveBufferSize( ):
KeepAlive method is to ensure the existence of a reference to an object that is at risk of being
prematurely reclaimed by the garbage collector

The ReceiveBufferSize property gets or sets the number of bytes that you are expecting to store in the
receive buffer for each read operation.

KeepAlive() and SendBufferSize( ):


KeepAlive method is to ensure the existence of a reference to an object that is at risk of being
prematurely reclaimed by the garbage collector

A send buffer size might delay the recognition of connection difficulties. Consider increasing the buffer
size if you are transferring large files, or you are using a high bandwidth, high latency connection (such
as a satellite broadband provider.)
ReceiveBufferSize( )

public int getReceiveBufferSize( )


Functionality
Returns the buffer size or the SO_RCVBUF (size of the buffer the kernel allocates to hold the
data arriving into the given socket) of socket.
Throws a SocketException - if there is an error in the underlying protocol, such as a TCP error.
Purpose
Returns the buffer size of socket.

public void setReceiveBufferSize(int size)


Functionality
Sets the SO_RCVBUF option to the given value for the specified socket.
Throws a SocketException - if there is an error in the underlying protocol, such as a TCP error.
Also IllegalArgumentException - if the size is set 0 or less.
Purpose
Sets the SO_RCVBUF option to the given value for the specified socket.

Comparison:
ReceiveBufferSize( ) and SendBufferSize( ):
The ReceiveBufferSize property gets or sets the number of bytes that you are expecting to store in the
receive buffer for each read operation.

A send buffer size might delay the recognition of connection difficulties. Consider increasing the buffer
size if you are transferring large files, or you are using a high bandwidth, high latency connection (such
as a satellite broadband provider.)

ReceiveBufferSize( ) and SoLinger( ):


The ReceiveBufferSize property gets or sets the number of bytes that you are expecting to store in
the receive buffer for each read operation.

SoLinger return the setting of SO_LINGER option of socket or enables a socket to toggle the
SO_LINGER option.

SendBufferSize( ):
public int getSendBufferSize( )
Functionality
The getSendBufferSize() method returns the value of the SO_SNDBUF option of the specified
Socket.
Throws a SocketException - if there is an error in the underlying protocol, such as a TCP error.
Purpose
This method returns the buffer size (SO_SNDBUF) used by the platform for output on this
socket.

public void setSendBufferSize(int size)


Functionality
Sets the SO_SNDBUF option to the given value for this socket.
The parameter size represents the size to which the send buffer size is set.
Throws a SocketException - if there is an error in the underlying protocol, such as a TCP error.
Also IllegalArgumentException - if the size is set 0 or less.
Purpose
Sets the SO_SNDBUF option to the given value for this socket.

Comparison:
SendBufferSize( ) and SoLinger( ):
A send buffer size might delay the recognition of connection difficulties. Consider increasing the buffer
size if you are transferring large files, or you are using a high bandwidth, high latency connection (such
as a satellite broadband provider.)

SoLinger return the setting of SO_LINGER option of socket or enables a socket to toggle the
SO_LINGER option.

SendBufferSize( ) and SoTimeout( ):


A send buffer size might delay the recognition of connection difficulties. Consider increasing the buffer
size if you are transferring large files, or you are using a high bandwidth, high latency connection (such
as a satellite broadband provider.)
SoTimeout( ) method returns/set the value of SO_TIMEOUT option of the socket.

SoLinger( )
public int getSoLinger( )
Functionality
This method returns the setting if the SO_Linger option is set else it returns -1 if the option is
disabled.
Throws a SocketException - if there is an error in the underlying protocol, such as a TCP error.
Purpose
Returns the setting for SO_LINGER option.

public void setSoLinger(boolean on, int linger)


Functionality
This method enables or disables the SO_LINGER option with the given linger time in seconds.
Throws a SocketException - if there is an error in the underlying protocol, such as a TCP error.
Also IllegalArgumentException - if the linger is set less than 0.
Purpose
This method enables or disables the SO_LINGER option with the given linger time in seconds.
Comparison:
SoLinger( ) and SoTimeout( ):
SoLinger return the setting of SO_LINGER option of socket or enables a socket to toggle
the SO_LINGER option.
SoTimeout( ) method returns/set the value of SO_TIMEOUT option of the socket
SoLinger( ) and TcpNoDelay( ):
SoLinger return the setting of SO_LINGER option of socket or enables a socket to
toggle the SO_LINGER option.

TcpNoDelay( ) method returns/set the value of TCP_NODELAY option of the socket

SoTimeout( ):
public int getSoTimeout( )
Functionality
Used to enable/disable SO_TIMEOUT with the specified timeout, in milliseconds.
Throws an IOException - if an I/O error occurs.
Purpose
Retrieve the setting for the SO_TIMEOUT.

public void setSoTimeout(int timeout)


Functionality
This method enables or disables the SO_TIMEOUT option with the given timeout value, in
milliseconds. 
The parameter timeout represents a specific timeout in milliseconds.
Throws a SocketException - if there is an error in the underlying protocol, such as a TCP error.
Purpose
enables or disables the SO_TIMEOUT option with the given timeout value, in milliseconds. 
.

Comparison:
SoTimeout( ) and TcpNoDelay( ):
SoTimeout( ) method returns/set the value of SO_TIMEOUT option of the socket

TcpNoDelay( ) method returns/set the value of TCP_NODELAY option of the socket

SoTimeout( ) and KeepAlive( ):


SoTimeout( ) method returns/set the value of SO_TIMEOUT option of the socket

KeepAlive method is to ensure the existence of a reference to an object that is at risk of being


prematurely reclaimed by the garbage collector

TcpNoDelay( )

public boolean getTcpNoDelay( )


Functionality
The method returns a Boolean value true if the TCP_NODELAY is enabled.
Throws a SocketException - if there is an error in the underlying protocol, such as a TCP error.
Purpose
The method returns the setting for SO_TIMEOUT option if it is enabled, else it returns false.

public void setTcpNoDelay(boolean on)


Functionality
Enable/disable TCP_NODELAY.
Throws a SocketException - if there is an error in the underlying protocol, such as a TCP error.
Purpose
The setTcpNoDelay () method of Java Socket class enables or disables the TCP_NODELAY
option.
Comparison:
TcpNoDelay( ) and KeepAlive( ):
TcpNoDelay( ) method returns/set the value of TCP_NODELAY option of the socket

KeepAlive method is to ensure the existence of a reference to an object that is at risk of being


prematurely reclaimed by the garbage collector

TcpNoDelay( ) and ReceiveBufferSize( ):


TcpNoDelay( ) method returns/set the value of TCP_NODELAY option of the socket

The ReceiveBufferSize property gets or sets the number of bytes that you are expecting to store in the
receive buffer for each read operation.

You might also like