What are the steps that are followed when two computers connect through TCP?

Solution:

There are the following steps that are performed when two computers connect through TCP.

  • The ServerSocket object is instantiated by the server which denotes the port number to which, the connection will be made.
  • After instantiating the ServerSocket object, the server invokes accept() method of ServerSocket class which makes server wait until the client attempts to connect to the server on the given port.
  • Meanwhile, the server is waiting, a socket is created by the client by instantiating Socket class. The socket class constructor accepts the server port number and server name.
  • The Socket class constructor attempts to connect with the server on the specified name. If the connection is established, the client will have a socket object that can communicate with the server.
  • The accept() method invoked by the server returns a reference to the new socket on the server that is connected with the server.
0 answers