Java Socket getInetAddress() method25 Mar 2025 | 2 min read 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. SyntaxParameterNA ReturnThe getInetAddress () method either returns the remote IP address to which the socket is connected or returns null if the socket is not connected. Example 1Output: Inet address: localhost/127.0.0.1 Port number: 1085 Example 2Output: Exception in thread "main" java.net.SocketException: Socket is closed at java.net.Socket.connect(Socket.java:566) at com.tpointtech.JavaSocketGetInetAddressExample2.main(JavaSocketGetInetAddressExample2.java:20) Next TopicJava Socket Class |
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 method The isBound () method of Java Socket class returns a Boolean value representing the binding state of the socket. This method would continue to return 'true' for a closed socket, if it was bound before being closed. Syntax public boolean isBound() Parameter NA Return The isBound () method would...
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 setKeepAlive() method of Java Socket class returns a Boolean value 'true' if the write-half of the socket connection has been closed successfully else it returns false. Syntax public void setKeepAlive (boolean on) throws SocketException Parameter The parameter 'on' represents whether the socket should be enabled or...
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 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 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 getOutputStream() method of Java Socket class returns an output stream for the given socket. If you close the returned OutputStream then it will close the linked socket. Syntax public OutputStream getOutputStream() throws IOException Parameter NA Return The getOutputStream() returns an output stream for writing bytes to this socket. Throws IOException-...
3 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 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
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