Java Socket setTcpNoDelay() method

The setTcpNoDelay () method of Java Socket class enables or disables the TCP_NODELAY option.

Syntax

Parameter

The parameter 'on' represents enables or disables the TCP_NODELAY option.

Return

NA

Throws

SocketException - if an error is there in the underlying protocol, such as a TCP error.

Example 1

Test it Now

Output:

SO_TIMEOUT option is enabled: true

Example 2

Test it Now

Output:

SO_TIMEOUT option is disabled

Example 3

Test it Now

Output:

Exception in thread "main" java.net.SocketException: Socket is closed
	at java.net.Socket.setTcpNoDelay(Socket.java:979)
	at com.javaTpoint.JavaSocketSetTcpNoDelayExample3.main(JavaSocketSetTcpNoDelayExample3.java:15)




Latest Courses