Java ServerSocket bind() methodThe bind() method of Java ServerSocket class binds the ServerSocket to the specified socket address, i.e. IP address and port number. If the specified address is null, the system will automatically pick up an ephemeral port and a valid local address to bind this socket. In the second syntax, the backlog argument is the requested maximum number of pending connections on the socket. The specified backlog should always be greater than 0. If the backlog's value is less than or equal to 0, then an implementation specific default value will be used. SyntaxParameter
ReturnNA ThrowsIOException- if the socket is already bound or bound if the bind operation fails SecurityException- if the SecurityManager is present and its checkListenmethod doesn't permit the operation IllegalArgumentException- if the endpoint is a SocketAddress subclass which is not supported by this socket Example 1Output: Local Socket Address: localhost/127.0.0.1:1085 Example 2Output: Exception in thread "main" java.net.SocketException: Socket is closed atjava.net.ServerSocket.bind(ServerSocket.java:359) atjava.net.ServerSocket.bind(ServerSocket.java:329) at com.javaTpoint.JavaServerSocketBindExample2.main(JavaServerSocketBindExample2.java:21) Example 3Output: Local Socket Address: localhost/127.0.0.1:1085 Example 4Output: Local Socket Address: localhost/127.0.0.1:1085 Channel: null
Next TopicJava ServerSocket
|