Establishing a socket connection requires at least one pair of sockets, one running on the client, called Clientsocket, and the other running on the server side, called ServerSocket.
The connection between sockets is divided into three steps: Server listening, client request, connection acknowledgement.
1, Server monitoring: Server-side sockets do not locate the specific client sockets, but in the status of waiting for the connection, real-time monitoring network status, waiting for the client connection request.
2, client request: Refers to the client socket to make a connection request, to connect to the target is the server-side socket.
To do this, the client's socket must first describe the socket of the server it is connecting to, indicate the address and port number of the server-side socket, and then make a connection request to the server-side socket.
3. Connection confirmation: When the server side socket is heard or received the connection request of the client socket, it responds to the request of the client socket, establishes a new thread, sends the description of the server end socket to the client, and once the client confirms the description, the two sides formally establish the connection.
While the server-side socket continues to be in the listening state, it continues to receive connection requests from other client sockets.
The difference between TCP/IP, Http, and socket