Two classes are generally used to create socket connections using Java: java.net.Socket and java.net.ServerSocket. The server application uses an instance of the ServerSocket class, and the client application uses an instance of the Socket class.
The ServerSocket is created first, identifying a port number where the server will listen for a connection. The ServerSocket will only listen for a connection on the host server where it is running.
The client application creates a Socket class instance, which accepts a combination of a host name or IP address and a port number as arguments to the constructor. If a successful connection is made, then an instance of the Socket class is created. This instance is then used to retrieve an