Socket Programming is becoming more and more popular among programmers. Socket provides the communication mechanism between two computers using TCP.
When the connection is made, the server creates a socket object on the end of the communication.
The client and the server can now communicate by writing to and reading from the socket. The java.net.Socket class represents a socket, and the java.net.ServerSocket class provides a mechanism for the server program to listen for clients and establish connections with them.
The java.net.ServerSocket class is used by server applications to obtain a port and listen to the client’s request.
The java.net.Socket class represents the socket that both the client and the server use to communicate with each other. The client obtains a Socket object by instantiating one, whereas the server obtains a Socket object from the return value of the accept() method.