当前位置:网站首页>Three handshakes and four waves of TCP protocol and why------ One two pandas
Three handshakes and four waves of TCP protocol and why------ One two pandas
2022-06-13 07:23:00 【One two pandas】
TCP Triple connection process
I haven't reviewed for a long time TCP Three handshakes, four waves , Review the .
SYN、RST It is used for connection establishment and clearing , contain SYN The message is called SYN Message segment .
When establishing a connection :
First step , Client's TCP First to the server side TCP Send a special TCP message . The message segment does not contain application layer data . The header of the message contains a flag bit SYN Be set to 1, At the same time, the customer service end selects a random serial number seq(client_isn) And put it at the beginning TCP SYN In the message segment , This message segment will be sent to the server . In a message segment SYN=1 Indicates that this is a connection establishment message ,seq Is the random serial number of the client .
The second step , once TCPSYN Of the message segment ip Datagram arrives at server host , The server will take it out of the datagram TCPSYN Message segment , For the sake of TCP Distribute TCP Caching and variables , And send the message segment allowing connection to the client . First, the flag bit of the message segment to be replied SYN Set as 1, Secondly, the first confirmation number field of the message segment is set to client_isn+1, namely ack=x+1; Finally, the server will select its own initial serial number (server_isn) namely seq=y, And place it in TCP In the sequence number field of the header of the message segment .( This message segment that allows connection actually indicates :“ I have received your SYN grouping , The group has an initial sequence number clien_isn. I agree to establish a connection . My own serial number is server_isn”), This segment is called SYNACK Message segment . Of the message segment SYN=1 Yes indicates that this is a connection establishment message ,ACK It is the confirmation of the client message segment ,seq=y The server sends its own initial serial number ,ack=x+1 It refers to the sequence number of the next byte expected to be received from the other party .
The third step , Upon receipt of SYNACK After the message , The client will also allocate cache and variables to the connection . The client sends another message segment to the server . This message segment confirms the connection allowed message segment of the server , The client will value server_isn+1 Placed in TCP To complete this work in the header confirmation field of the message segment .SYN Be set to 0, Because the connection has been established .
among ACK It is the confirmation of the server-side message segment ,seq=x+1 It is the sequence number of the next message transmitted to the other party , That is to synchronize the serial number given after receiving the server message last time ,ack=y+1 Is the sequence number of the next byte expected from the server .
Why do I need three connections , Can't secondary connection ?
The necessity of triple connection :
The reason a : To prevent duplicate connections
TCP The third handshake is mainly used to prevent the repeated connection caused by the old connection .
Without a third handshake , The server can only choose to establish a connection or reject a connection , But the server doesn't know whether the connection is illegal , So every time I receive a SYN It's going to create a new connection , The server will establish multiple redundant invalid links , Cause unnecessary waste of resources (SYN Flooding attack ). if TCP It's three handshakes , Then the customer receives ack=x+1 You can determine whether the current connection is a historical connection , If it's a historical connection , The customer service terminal will send a termination message RST, Tell the server to terminate this connection , If it is not a historical connection , Then send instructions to the server to establish the connection .
Popular said :
If the client makes a connection request , However, due to network fluctuation, the server did not receive the request for connection from the client , So the client sends a connection request again , The client and server establish a connection after two handshakes . Both sides begin to transmit data , After the data transmission is completed , Both parties disconnect . After a while , The connection request that was originally suspended in the network transmission arrived at the server . The server thinks that the client has sent a new connection request , So it sends a confirmation message segment to the client , Agree to establish a connection ( Two handshakes only require the server to send a confirmation message segment , Just set up the connection ). At this time, the server is waiting for the data sent by the client , Has been wasting system resources .
Reason two : To synchronize the initialization sequence
First, the client sends a seq=200 To the server , The server will return a message after receiving it ack=200+1 The confirmation of , When the customer service end sends many datagrams to the server , Because of the Internet , Packets do not arrive in the order they were sent . When the server confirms the received packets, it will only confirm one by one , Like sending ack=900+1 Confirmation datagram for , Just before 900 The datagram of serial number has been received . If only received seq=900 And the next one to arrive is seq=1000 Data packets of , Generally, it will be discarded or kept until all out of order data is reported .
TCP It is a stable network transmission protocol , It needs a serial number to ensure its stability . This serial number is used to prevent duplication or omission of datagrams , And solve the problem of reverse datagram order . When the client sends a message segment with initial serial number to the server , The server needs to answer a question that has received the initial serial number ACK Reply message , The datagram sent by the server also contains the initial serial number of the server , You also need to get a reply from the client , In this way, the serial numbers of both parties can be synchronized .
TCP Four waves
When the client application process sends a command to close the connection , client TCP It will send a message to the server TCP Send a message segment with a special flag bit , This special flag bit is FIN=1; When the server receives this message segment, it sends a confirmation message segment to the sender , The server then sends its own termination segment , Its FIN The flag bit is also set to 1. Last , The client confirms the termination message of the server . This time TCP All connected resources are released on both hosts .
Visit the blog for details :TCP Four waves
Self study notes .
边栏推荐
- Xuanwu cloud technology passed the listing hearing: the performance fluctuated significantly, and chenyonghui and other three were the controlling shareholders
- Micro isolation (MSG)
- Nfv basic overview
- RT-Thread 模拟器 simulator LVGL控件:slider 控件
- 领先企业的管理实践证明,企业可持续发展的核心是什么?
- 关于oracle的函数。
- RT thread simulator lvgl control: button button event
- C#合并多个richtextbox内容时始终存在换行符的解决方法
- Can flush open a stock account? Is it safe?
- Is it safe to open an account online in Hangzhou?
猜你喜欢
![[RS-422 and RS-485] RS-422 and RS-485 serial interface standard](/img/08/e50df07d387b2f2d57a518caedc795.jpg)
[RS-422 and RS-485] RS-422 and RS-485 serial interface standard

WWDC2022最大的亮点: MetalFX

Powerdispatcher reverse generation of Oracle data model

Login registration

Related operations under Oracle Database

Oracle problem: the data in the field is separated by commas. Take the data on both sides of the comma

How to write an amazing design document?

关于#数据库#的问题:PGADMIN4 编辑sql窗口问题
![[weak transient signal detection] matlab simulation of SVM detection method for weak transient signal under chaotic background](/img/11/d6cd333a2fa56af2dc61b7597f1ada.png)
[weak transient signal detection] matlab simulation of SVM detection method for weak transient signal under chaotic background

微隔离(MSG)
随机推荐
redis-6. Redis master-slave replication, cap, Paxos, cluster sharding cluster 01
AQS - detailed explanation of reentrantlock source code
powerdisgner逆向生成oracle数据模型
通过函数seaborn.cubehelix_palette生成顺序调色板
Fundamentals of assembly language: register and addressing mode
c#高级编程-特性篇
Test development programmers, are you still confused? You can't define yourself as a yard farmer
Through the function seaborn cubehelix_ Palette build order palette
Issues related to C # delegation and events
Is it safe for Hangzhou Securities to open an account?
Deploy RDS service
5xx series problem solving
Related operations under Oracle Database
百货中心供应链管理系统
The 'yarn' item cannot be recognized as the name of a cmdlet, function, script file, or runnable program
RT-Thread 模拟器 simulator LVGL控件:button 按钮事件
TiDB Lightning
Relevant knowledge under WinForm
汇编语言基础:寄存器和寻址方式
redis-0. Introduction to redis and NiO principle (random talk)