All About Class ServerSocket in Java



ServerSocket class implements server sockets.A server socket waits for requests to come in over network.It perform some operation based on that request and then possibly return a result to the requestor.Actual work of the server socket is performed by an instance of the SocketImpl class. An application can change the socket factory that creates the socket implementation to configure itself to create dockets appropriate to local firewall.

The structure of the class ServerSocket is given as:

public final class java.net.ServerSocket extends java.lang.Object{
//contructors
public ServerSocket(int port);
public ServerSocket(int port,int count);
//methods
public Socket accept();
public void close();
public InetAddress getInetAddress();
public int getLocalPort();
public static void setSocketFactory(SocketImplFactory fac);
public String toString();
}
 
public ServerSocket(int port);
This creates a server socket on the specified port.A port (of 0) object creates a socket on any free port.The maximum queue length for incoming connection indication arrives when the queue is full,the connection request is refused.If the application has specified a server socket factory,the factory's createSocketImpl() method is called to create the actual socket implementation.Otherwise a plain socket is created.It may throw IOException if an I/O error occurs while opening the socket.
public ServerSocket(int port,int count);
creates a server socket and binds it to the specified local post number.A port number of 0 creates a socket on any free port available.The maximum queue length for incoming connection request indication( request to connect) is set to count parameter.If a connection indication arrives when the queue is full,the connection is refused.If the application has specified a server socket factory,the factory's createSocketImpl() method is called to create the actual socket implementation.Otherwise a plain socket is created.It may throw IOException if an I/O error occurs while opening the socket.
All About Class ServerSocket in Java All About Class ServerSocket in Java Reviewed by Animesh Chatterjee on October 12, 2018 Rating: 5

No comments:

Powered by Blogger.