TCP/IP Detailed learning notes--establishment and termination of TCP connections

Source: Internet
Author: User
1.TCP Connection Establishment             Set Host B to run a server process that first emits a passive open command, telling its TCP to be ready to receive successive requests from the client process, and then the service process is in the listening state. Continuously detect whether there is a customer process to initiate a continuous request, if any, to respond. The client process runs in host A, he first sends the active command to his TCP, indicating that he wants to establish a transport connection to a certain port of an IP address, as follows:      1) TCP of Host A sends a connection request message segment to TCP of Host B. The synchronization bit SYN in its header should be set to 1, and an ordinal x should be selected, indicating that the ordinal number of the first data byte is x when the data is transmitted later.      2) Host B TCP receives the connection request message segment and, if agreed, plays a confirmation. In the confirmation segment should be SYN set to 1, the confirmation number should be x+1, but also for their own choice of a serial number y      3 Host a TCP received this message segment, but also to B give confirmation, its confirmation number is y+1       4 Host A's TCP notification upper level application process, the connection has been established, when Host B TCP receives the host a confirmation, also informs the upper level application process, the connection establishes.   2.TCP Connection release             After the data is transferred, both sides of the communication can send a request to release the connection. The process of releasing the connection is as follows:      1) The application process of host A sends a release connection request to its TCP before sending the data. TCP notifies the other party to release a connection from A to B, the end bit of the TCP segment header destined for Host B is set to 1, and the ordinal U equals the ordinal of the last byte of the transmitted data plus 1.      2) Host B TCP receives the release of the connection notification and sends a confirmation, its serial number is u+1, and the application process is notified, so that A to B connection is released and the connection is in a semi shutdown state. Host B is not receiving data from host A, but Host B also sends data to a, and host a will still need to send confirmation if it receives the data correctly.      3 The application process notifies TCP to release the connection after Host B sends the data to host a. The connection release segment emitted by Host B must set the Terminator bit to 1 and make its serial number W equal to the last byte of the previous transmitted data, plus 1, and must repeat theAck=u+1 that have been sent for the second time.      4) host A sends a confirmation to the connection release segment of Host B, and the ACK is 1,ack=w+1, seq=u+1. In this way, the reverse direction from B to A is released, and host A's TCP is reported to its application process, and the entire connection is released.   3. Note the problem three times when the handshake establishes the connection, the sender sends the confirmation again the necessity mainly is to prevent the invalid connection request message segment to suddenly pass to B, thus produces the error. It is assumed that the first connection request message segment issued by a has not been lost, but has been stranded for a long time at some network nodes and has been delayed until a certain time after the release of the connection to arrive at B, which is already a defunct message segment. However, after receiving this invalid connection request segment, B is mistaken for a new connection request and sends a confirmation message to a and agrees to establish the connection. Assuming that there is no three handshake, a new connection is established as soon as B confirms it, so that a lot of the resources of B are wasted by waiting for a to send the data. Four times waving the connection, waiting for the meaning of 2MSL first, in order to ensure that a send the most of the ACK message segment can reach B. This ACK segment is likely to be lost so that B in the Last-ack state does not receive confirmation of the sent fin and ACK segments. B will time out to retransmit the fin and ACK segment, and a will be able to receive the retransmission Ack+fin message segment within 2MSL. Then a retransmission confirmation. Second, is to prevent the above mentioned invalid connection request message segment appears in this connection, a after sending the most of the ACK message segment, and then through 2MSL, you can make the connection duration of the time generated by all the message segments from the network disappeared. The steps required for the establishment and release of 4.TCP finite state machines       Connections can be expressed in a finite state machine, which has 11 states. There are legitimate events in every state, and some action may be necessary when a legitimate event occurs. When other events occur, an error is reported.

State

Description

CLOSED

Off state, no connection activity or in progress

LISTEN

Listening status, the server is waiting for the connection to enter

SYN Rcvd

Received a connection request, not confirmed

SYN SENT

A connection request has been made pending confirmation

Established

Connection established, normal data transfer status

FIN Wait 1

(active shutdown) has sent a shutdown request pending confirmation

FIN Wait 2

(active shutdown) receive the other close confirmation, wait for the other close request

TIMED wait

Completes bidirectional shutdown, waits for all groupings to die

CLOSING

Both sides try to close at the same time, waiting for each other to confirm

Close wait

(passive shutdown) received the other close request, has been confirmed

Last ACK

(passive shutdown) waits for the last shutdown confirmation and waits for all packets to die

The transition of TCP establishment and release as shown in the figure:

Customer process change process (thick solid line) connection establishment: Set up a host of client process to initiate a connection request (active open), when the local TCP entity on the creation of Transmission Control Fast (TCB), send a SYN 1 message, into the syn_sent state. When a SYN and ACK from the process is received, TCP sends the last ACK in the three handshake to enter the state established that the connection has been established. Connection release: Set to run client process host local TCP entity sends a message with a fin 1, waiting for the acknowledgment ack to arrive, at which time the state becomes fin_wait_1. When the client process host receives a confirmation ACK, the connection in one Direction is closed. The state becomes fin_wait_2. When the host running the client process receives a message with a fin set of 1 that is sent by the host running the server process, it should respond with a confirmation ack, which is another connection shutdown. However, TCP has to wait for some time before deleting the previously established connection record. Returns to the initial closed state, in order to ensure that all packets on the original connection have disappeared from the network. The process of server process change (thick dashed line) connection establishes: The server process sends out passively to open, enters listens the state listen. After receiving the SYN 1 connection request message, send a confirmation ack, and the SYN in the message is also set to 1, then enter the SYN_RCVD state. When you receive the last acknowledgment ack of three handshake, it becomes established state. Connection release: When the client process data has been delivered. Send the FIN 1 message to the server process, into the close_wait state. The server process sends the FIN segment to the client process, and the status changes to Last_ack state. When an ACK is received from the client process, the server process releases the connection. Deletes a connection record. Return to the original closed state.

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.