Java Socket toString() method25 Mar 2025 | 2 min read The toString() method of Java Socket class converts this socket to a String. SyntaxParameterNA OverridesThe toString() method in class Object ReturnThe toString() method returns the string representation for the given socket. Example 1Output: Inet address: localhost/127.0.0.1 Port number: 1085 Socket[addr=localhost/127.0.0.1,port=1085,localport=1085] Example 2Output: Inet address: localhost/127.0.0.1 Port number: 1085 Socket[addr=localhost/127.0.0.1,port=1085,localport=1085] Example 3Output: Exception in thread "main" java.net.SocketException: Socket is not connected at java.net.Socket.shutdownOutput(Socket.java:1553) at com.tpointtech.JavaSocketToStringExample3.main(JavaSocketToStringExample3.java:11) Next TopicJava Socket Class |
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 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 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 getSendBufferSize () method of Java Socket class returns the buffer size(SO_SNDBUF) used by the platform for output on this socket. Syntax public int getSendBufferSize () Parameter NA Return The getSendBufferSize () method returns the value of the SO_SNDBUF option of the specified Socket. Throws SocketException - if an error...
2 min read
Java Socket getReuseAddress () method The getReuseAddress () method of Java Socket class tests whether the SO_REUSEADDR option is enabled or not. It throws SocketException if finds an error in the underlying protocol, such as a TCP error. Syntax public boolean getReuseAddress() Parameter NA Return The getReuseAddress () method returns a...
2 min read
Java method The getRemoteSocketAddress () method of Java Socket class returns the address of the endpoint of the specified socket if it is connected else it will return null if this socket is not connected. Syntax public SocketAddress getRemoteSocketAddress () Parameter NA Return The getRemoteSocketAddress () method either returns the SocketAddress...
3 min read
Java method The setSoLinger() method of Java Socket class enables or disables the SO_LINGER option with the given linger time in seconds. It is used to specify how the close() method affects socket using a connection-oriented protocol. The timeout value is platform-specific, and this setting...
4 min read
Java 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 public int getSoLinger () Parameter NA Return The getSoLinger () method returns the setting for...
3 min read
Java method The setOOBInline() method of Java Socket class enables or disables the SO_OOBInline. By default, the SO_OOBInline option is disabled. Syntax public void setOOBInline (Boolean on) throws SocketException Parameter The 'on' represents whether the SO_OOBInline option should enabled or not. Return NA Throws SocketException - if there is an error in the...
2 min read
Java Socket isClosed () method The isClosed () method of Java Socket class returns the closed state of the socket. Syntax public boolean isClosed () Parameter NA Return The isClosed () method would return a Boolean value 'true' if the socket has been closed successfully. Example 1 import java.io.IOException; import java.net.*; public class JavaSocketIsClosedExample1 { ...
1 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