1.

Role of Java Sockets

Answer»

The Java Sockets are USED for communication between two computers using the TCP PROTOCOL. The communication between the client and server occurs when they read from and write to the sockets as required. The class java.net.Socket provides a representation for sockets in Java and the class java.net.ServerSocket allows the server programs to listen for clients and create connections with them.

The steps to create a TCP connection between two computers using sockets is given as follows:

  1. A ServerSocket object is instantiated by the server and this denotes the port number for communication.
  2. Then the accept() method of the ServerSocket class is invoked by the server. This method waits until the till the TIME the client can connect to the server on the specified port.
  3. The client instantiates a Socket object while a server is waiting. This object specifies the server name as well as the port number.
  4. The Socket class constructor tries to connect the client and the server on the required port number. After communication ESTABLISHMENT, the client can communicate with the server using a Socket object.
  5. The accept() method on the server side returns a reference to the socket that is connected to the client’s socket.

The communication can occur using the Output stream and INPUT stream after the connections are established.



Discussion

No Comment Found