Java Socket toString() methodThe 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 1Test it NowOutput: Inet address: localhost/127.0.0.1 Port number: 1085 Socket[addr=localhost/127.0.0.1,port=1085,localport=1085] Example 2Test it NowOutput: Inet address: localhost/127.0.0.1 Port number: 1085 Socket[addr=localhost/127.0.0.1,port=1085,localport=1085] Example 3Test it NowOutput: Exception in thread "main" java.net.SocketException: Socket is not connected at java.net.Socket.shutdownOutput(Socket.java:1553) at com.javaTpoint.JavaSocketToStringExample3.main(JavaSocketToStringExample3.java:11) 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