Java Socket getInetAddress() methodThe 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 1Test it NowOutput: Inet address: localhost/127.0.0.1 Port number: 1085 Example 2Test it NowOutput: Exception in thread "main" java.net.SocketException: Socket is closed at java.net.Socket.connect(Socket.java:566) at com.javaTpoint.JavaSocketGetInetAddressExample2.main(JavaSocketGetInetAddressExample2.java:20) 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