What is a socket? Brief tcp socket-based communication protocol process?

 English Socket original meaning is "hole" or "socket." Commonly referred to as "socket" is used to describe IP address and port, is the handle of a communication link,

It can be used to implement communication between different virtual machine or on different computers.

Hosts on the Internet generally running multiple software services, while providing several services . Each service will open a Socket, and bind to a port , different port corresponding to the different services.

 

Tcp socket communication process based protocol:

1) The server first with the socket function to create a socket, listen for the completion of communication with the socket. 
2) bind with a function to bind the IP address and port number. Because the local computer may have multiple URLs and IP, IP and each port has multiple ports. You need to specify an IP and port monitoring. 
3) The server calls the listen function, so that this port and IP server in a listening state, waiting for client connections. 
4) The client establish a socket with a socket function, set the remote IP and port. 
5) The client calls the connect function to connect the remote computer specified port. 
6). With the accept function to accept server connections to remote computers, communication is established between the client. 
7). After the connection is established, the client with the write function to write data to the socket. The read function can also be used to read data sent by the server. 
8). The server reads the client data transmitted by the read function, the data may be transmitted with a write function. 
9). After the completion of the communication, with the close function and socket connection.

Guess you like

Origin www.cnblogs.com/Rivend/p/12047299.html