Advance Java

Learn New things from Rixosys

Server Sockets

Server Sockets

In common language we can say that the sockets are just like an end-point of two-way communication link over the network between two programs. Socket classes are used to establish a connection between client program and a server program. In java there is a package, which provides two types of classes- first is ordinary socket, which implement the client side connection and second is server socket, which implement the server side connection.

In Java there are many socket class that is used for creating a Server applications. ServerSockets are quite different from normal Sockets. The main work of ServerSocket class is to wait for a request of connection by the client and connect them on published ports and then possibly returns a result to the requester. The SocketImpl is a common superclass of all classes that actually implement sockets. It is used to create both client and server sockets.

There are some constructors that might throw an IOException under adverse conditions. Some of the constructors are as under:

ServerSocket(int port)

Creates server socket on the specified port with a queue length of 50.

ServerSocket(int port, int maxQueue)

Creates a server socket on the specified port with amaximum queue length of maxQueue.

ServerSocket(int port, int maxQueue,InetAddress localAddress)

Creates a server socket on the specified port with amaximum queue length of maxQueue. On a multihomed host, localAddress specifies the IP address to which this socket binds.