Java Socket getTcpNoDelay() method

The getTcpNoDelay () method of Java Socket class returns the setting for SO_TIMEOUT option if it is enabled, else it returns false.

Syntax

Parameter

NA

Return

The getTcpNoDelay () method returns a Boolean value 'true' if the TCP_NODELAY is enabled.

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 enabled: false

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.JavaSocketGetTcpNoDelayExample3.main(JavaSocketGetTcpNoDelayExample3.java:14)




Latest Courses