Java Socket getRemoteSocketAddress() methodThe 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. SyntaxParameterNA ReturnThe getRemoteSocketAddress () method either returns the SocketAddress indicating the remote endpoint of the socket if the socket is connected else it returns null if the socket is not connected. Example 1Test it NowOutput: Local Port number: 1085 Remote socket address: localhost/127.0.0.1:1085 Example 2Test it NowOutput: Remote socket address: null Example 3Test it NowOutput: Exception in thread "main" java.net.ConnectException: Connection refused: connect at java.net.DualStackPlainSocketImpl.connect0(Native Method) at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:79) at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350) at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206) at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188) at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172) at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) at java.net.Socket.connect(Socket.java:589) at java.net.Socket.connect(Socket.java:538) at com.javaTpoint. JavaSocketGetRemoteSocketAddressExample3.main( JavaSocketGetRemoteSocketAddressExample3.java:15) Next TopicJava Socket Class |
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