Java Socket getLocalSocketAddress() method25 Mar 2025 | 2 min read 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. SyntaxParameterNA ReturnThe getLocalSocketAddress() method returns:
Example 1Output: Local Port number: 1085 Local socket address: /127.0.0.1:1085 Example 2Output: Local Port number: 1085 Local socket address: /192.168.0.102:1085 Example 3Output: Local socket address: null Next TopicJava Socket Class |
Java method The getInetAddress() method of Java Socket class returns the address to which the socket is connected. If the socket is being closed, this method will return the connected address after the socket is closed. Syntax public InetAddress getInetAddress () Parameter NA Return The getInetAddress () method either returns the...
3 min read
Java method The setTcpNoDelay () method of Java Socket class enables or disables the TCP_NODELAY option. Syntax public void setTcpNoDelay (boolean on) throws SocketException 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...
3 min read
Java method The getPort() method of Java Socket class returns the remote port number to which the socket is connected. This method will return the port number even after the socket is closed. Syntax public int getPort () Parameter NA Return The getPort() method either returns the port number to which...
2 min read
Java method The shutdownOutput() method of Java Socket class disables the output stream for the specified socket. If the socket output stream is written after invoking the shutdownOutput() method on the socket, the stream will throw an IOException. Syntax public void shutdownOutput () throws IOException Parameter NA Return NA Throws IOException...
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 setTrafficClass() method of Java Socket class sets the traffic class or type-of-service in the IP header for packets sent from the specified socket. The parameter (tc) should be in the range from 0 to 255(0<=tc<=255) else an IllegalArgumentException will be thrown. Syntax public void...
3 min read
Java method connect(SocketAddress endpoint) The connect() method of Java Socket class connects the specified socket to the server. Syntax public void connect(SocketAddress endpoint) throws IOException Parameter The parameter 'endpoint' represents the SocketAddress. Return NA Throws IOException - if an error occurs during the connection. IllegalBlockingModeException - if this socket has an associated channel and the...
5 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 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 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