Java Socket setSoTimeout() method25 Mar 2025 | 2 min read The setSoTimeout () method of Java Socket class enables or disables the SO_TIMEOUT option with the given timeout value, in milliseconds. The timeout value should be greater than 0 otherwise, it will throw an error. SyntaxParameterThe parameter 'timeout' represents a specific timeout in milliseconds. ReturnNA ThrowsSocketException - if an error is there in the underlying protocol, such as a TCP error. Example 1Output: Timeout value: 90987789 Example 2Output: Timeout value: 0 Example 3Output: Exception in thread "main" java.lang.IllegalArgumentException: timeout can't be negative at java.net.Socket.setSoTimeout(Socket.java:1139) at com.tpointtech.JavaSocketSetSoTimeoutExample3.main(JavaSocketSetSoTimeoutExample3.java:13) Example 4Test it NowOutput: Exception in thread "main" java.net.SocketException: Socket is closed at java.net.Socket.setSoTimeout(Socket.java:1137) at com.tpointtech.JavaSocketSetSoTimeoutExample4.main(JavaSocketSetSoTimeoutExample3.java:16) Next TopicJava Socket Class |
Java method The isInputShutdown () method of Java Socket class returns a Boolean value 'true' if the read-half of the socket connection has been closed, else it returns false. Syntax public boolean isInputShutdown () Parameter NA Return The isInputShutdown () method returns a Boolean value 'true' if the socket has been...
3 min read
Java method The getLocalSocketAddress() method of Java Socket class returns the address of the endpoint to which this socket is bound. This method will continue to return an InetSocketAddress even after the socket is closed. Syntax public SocketAddress getLocalSocketAddress () Parameter NA Return The getLocalSocketAddress() method returns: the SocketAddress, representing the...
3 min read
Java method The get00BInline() method of Java Socket class tests whether the S0_00BINLINE option is enabled or not. Syntax public boolean get00BInline () Parameter NA Return The get00BInline() method returns a Boolean value 'true if the S0_00BINLINE is enabled else it returns false. Throws SocketException - if an error is there in...
2 min read
Java method The bind() method of Java Socket class binds the socket to a local address. If the specified address is null, then the system will automatically pick up a port number and a valid local address to bind with the socket. Syntax public void bind(SocketAddress bindpoint)...
3 min read
Java method The getTrafficClass() method of Java Socket class returns the traffic class or type-of-service in the IP header sent from the specified Socket. Syntax public int getTrafficClass () Throws SocketException Parameter NA Return The getTrafficClass () method returns the traffic class or type-of-service. Throws SocketException - if there occurs an error while...
2 min read
Java method The getLocalPort() method of Java Socket class returns the local port number to which the specified socket is bound. If the socket was being closed, this method will return the connected port number after the socket is closed. Syntax public int getLocalPort() Parameter NA Return The getLocalPort () method...
2 min read
Java method The sendUrgentData() method of Java Socket class sends one byte of urgent data on the socket. The byte should be the lowest eight bits of the data parameter. Syntax public void sendUrgentData (int data) throws IOException Parameter The "data" parameter represents the byte of data to send. Return NA Throws IOException...
4 min read
Java method The getKeepAlive() method of Java Socket class tests whether SO_KEEPALIVE option is enabled or not. Syntax public boolean getKeepAlive () Parameter NA Return The getKeepAlive() method either returns a Boolean indicating whether SO_KEEPALIVE option is enabled or not. Throws SocketException - if there is an error in the underlying protocol, such...
2 min read
Java method The getTcpNoDelay () method of Java Socket class returns the setting for SO_TIMEOUT option if it is enabled, else it returns false. Syntax public boolean getTcpNoDelay () Parameter NA Return The getTcpNoDelay () method returns a Boolean value 'true' if the TCP_NODELAY is enabled. Throws SocketException - if an error is...
2 min read
Java method The toString() method of Java Socket class converts this socket to a String. Syntax public void toString() Parameter NA Overrides The toString() method in class Object Return The toString() method returns the string representation for the given socket. Example 1 import java.io.IOException; import java.net.*; public class JavaSocketToStringExample1 { ...
3 min read
We request you to subscribe our newsletter for upcoming updates.
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India