一般面试网络,程序员基本都会问到关于三次握手,四次握手。
四次握手下次讲解。
本人经历好几次面试都被问到,一直没有认真搞明白,这次全面查阅书籍与对比博客进行了一下总结,希望看官仔细看完后能得到收获。
1. TCP packet header format
2. explain the format field
Source Port: Source Port application process. Their ports, such is 64531. 16, so only the port number from 0 to 65535
Destination port: port number of the target host. The same is 16.
Reference: (SEQ ID NO Sequence Number) is generally referred to as SEQ . 32-bit field length. When the value is greater than 2 to the power 32, return 0.
Acknowledgment number: (the ACK acknowledgment number Acknowledgement Number) is generally referred to as ACK . Note the lowercase. So as not to conflict following the ACK flag. No. looked forward to receiving the other first data field of the next segment .
Flag (In Flag) . 6 th
URG : (Emergency) Emergency effective, need fast retransmit
ACK :( acknowledgment) packet to respond after connection, ACK 1
PSH :( push) the recipient should be the message to the upper layer of the protocol as soon as possible, without waiting for the full.
The RST :( reset) reconnecting
The SYN :( synchronized) transmits a connection
FIN :( termination) connection release
3. TCP connection is established
The first handshake
Customer A sends a synchronization flag SYN = TCP data segment 1. While the initial sequence number indicated in this paragraph (Initial Sequence Number) ISN is a time-varying random values, i.e., the SYN =. 1, SEQ = X . In this case the customer A enters the SYN-SENT state
The second handshake
After receiving the server sends back a SYN packet acknowledgment. Flag data packet the ACK =. 1 , while the acknowledgment number (ACK) indicating that the client A server expects to receive next data segment number, i.e., ACK = X +. 1 (a previous segment of data has been received without errors)
Furthermore, a flag bit SYN = 1, and the server's initial sequence number y. I.e., the SYN =. 1, Y = SEQ .
At this time, the server B to enter the SYN-RCVD state,
A customer enters the ESTABLISHED state
Third handshake
A customer sends back an acknowledgment segment.
Flag the ACK =. 1 . SEQ. 1 = x + (x own first handshake i.e. SEQ), ACK = Y +. 1 (SEQ ID NO server B y)
The next step is to send and receive data with each other.
Handshake phase:
No. | direction | seq | ack | SYN | ACK |
---|---|---|---|---|---|
1 | A->B | 10000(x) | 0 | 1 | 0 |
2 | B->A | 20000 (y) | 10001 = 10000 + 1 (ACK = x + 1) | 1 | 1 |
3 | A->B | 10001 (x=x+1) | 20001 = 20000 + 1 (ACK = y + 1) | 0 | 1 |
I hope this knowledge can bring some help, if you have any questions, please add group 641 792 143 exchanges and learning or attention to micro-channel public number programmers dry area
Road have been heard, industry specializing in surgery, I hope you have educated us
following is a number of two-dimensional public code