[Network programming] the illustration of TCP connection and disconnection API, tcpapi

Source: Internet
Author: User

[Network programming] the illustration of TCP connection and disconnection API, tcpapi

Three-way handshake

Create a tcp connection:
0. The server must be prepared to accept external connections. Call the socket, bind, and listen functions to enable passive open );

1. The client callsActively open the connect function(Active open ). The customer sends a SYN packet to inform the server end of the initialization serial number of the data sent in the connection. Generally, the SYN Packet does not carry data.(Call the connect function to enable and block the connection and wait for handshake confirmation)

2. the server must confirm the customer's SYN, and the server must also send a SYN packet, which contains the initialization serial number of the data that the server will send in the same connection, the server sends SYN and ACK to the customer using a single packet; (The Server originally blocked the listen function. Because the connect function enables the listen function to return the result, the first handshake is established, and the Server continues to execute the function, blocking the accept function)

3. The customer must send an ACK to confirm the server's SYN;(If the connect function is returned successfully, it indicates that the client has confirmed that three handshakes have been established (at this time, the Server does not know before receiving the confirmation from the client). The client sends a signal to allow the Server to return the accept function, at this time, three handshakes are successfully performed)




Split up four times
1. an application first calls the close function, which is called active close. The tcp at this end sends a FIN message, indicating that the data has been sent;
2. passive close is executed on the other end of the received FIN. The FIN is confirmed by tcp. Its application is passed to the receiver application as a file terminator (placed after any data waiting for the application process to receive );
3. After a period of time, the application process receiving the file Terminator will call the close function to close its set of interfaces and send a FIN packet;
4. The original sender tcp who received the FIN message confirms the message;




This article is collected by Cout_Sev

Reprinted with the source

Http://blog.csdn.net/cout_sev

Thank you!



What is the process of establishing and disconnecting tcp?

Right-click the website and select Properties.
Open the local connection. In general, the installation of the Internet Protocol includes the IP/TCP protocol. When a network terminal device is connected, the IP address can be automatically requested. Of course, you can also use dynamic settings.
Disconnected.

Is the connection disconnected through vc network programming?

The receiving and sending function of the socket is called and the returned result is incorrect. You can see that the network is abnormal.
If you want to know the network status but do not send and receive data for a long time, you can implement a heartbeat mechanism, that is, to send a small package every several seconds, and check the return value to determine the network status.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.