Java Socket getSoLinger() method

The getSoLinger () method of Java Socket class returns the setting if the SO_Linger option is set else it returns -1 if the option is disabled.

This method only affects the setting for SO_LINGER.

Syntax

Parameter

NA

Return

The getSoLinger () method returns the setting for SO_LINGER option.

Throws

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

Example 1

Test it Now

Output:

Send Buffer size: -1

Example 2

Test it Now

Output:

Send Buffer size: -1

Example 3

Test it Now

Output:

Exception in thread "main" java.lang.IllegalArgumentException: invalid value for SO_LINGER
	at java.net.Socket.setSoLinger(Socket.java:1021)
	at com.javaTpoint.JavaSocketGetSoLingerExample3.main(JavaSocketGetSoLingerExample3.java:13)




Latest Courses