Connection handshake:
1. Client sends establish connection request 2. The server confirms the connection request 3. The client confirms that the above 3 steps have been connected after completing the break handshake using send recv: If you want to disconnect correctly, you must go through 4 handshakes. 1. The client sends a request to stop the TCP connection request 2. After the server receives the request, it closes the socket 3. The server sends the reverse request client to close the socket connection 4. The client confirms the service-side request and closes the socket connection.    TCP is a connection-oriented service, the connection-oriented service is the abstraction of the Telephony system service pattern, every time the complete data transmission must be established connection, data transmission and termination connection 3 processes, TCP connection process called three times handshake, Take a look at the three-time handshake with this process TCP three handshake process 1 host a by sending to host B a data segment containing the serial number of the flag bit to host B, to host B request to establish a connection, through this data segment, host a tells Host B two things: I want to communicate with you; You can use the serial number as the starting data segment to respond to me. 2 Host B receives a request from host A, and responds to host A with a data segment with a ACK (ACK) and a synchronous sequence number (SYN) flag bit, and also tells host a two things: I have received your request, you can transfer data; Which pins XLR serial number are you going to use as the starting data segment to respond to my 3 when host a receives this data segment, it sends a confirmation response confirming that the data segment of Host B has been received: "I have received a reply, I am now going to start transmitting the actual data so 3 times the handshake is complete, host A and Host B You can transfer data. 3-time handshake features no application layer of Data SYN This flag bit is only placed when the TCP build connection will be 1 handshake completion after the SYN flag bit is set 0  TCP establish a connection to do 3 handshake, and disconnect to do 4 times, This is due to the semi-shutdown of TCP because the TCP connection is full-duplex (that is, the data can be passed in two directions at the same time), so each direction is closed when it is closed, and this one-direction closure is called half-closed. The method of closing is when a party finishes its data transfer, Send a fin to the other party to announce the connection that will terminate this direction. When one side receives a fin, it must notify the application layer that the TCP connection has terminated the data transfer in this direction, and the sending of fin is usually the result of the application layer shutting down. 4 Break 1 When host a completes the data transfer, the control bit fin 1, the request to stop the TCP connection 2 Host B receives fin response to it, confirm that the side of the TCP connection will be closed, the ACK will be 13 by the B end of the reverse direction of the shutdown request, the fin 14 Host a confirms the request to Host B, and the ACK is set to 1, bothTo the end of the closing. By the TCP three handshake and four disconnects, it can be seen that TCP uses the connection-oriented communication method, which greatly improves the reliability of data communication, so that the transmitting data end and the receiving end have the interaction before the official transmission, which lays a reliable foundation for the formal transmission of the data.
iOS Development Socket (i)