当前位置:网站首页>Tcp/ip network communication knowledge record
Tcp/ip network communication knowledge record
2022-06-12 14:12:00 【Panda general】
TCP/IP characteristic :
① Connection oriented transport layer protocol , A connection must be established before use , The established connection must be released after the transmission ;
② Every one of them TCP Connections can have only two endpoints , one-on-one ;
③TCP Provide reliable delivery of services , adopt TCP Continuously transmitted data , No mistakes 、 No loss 、 Do not repeat and arrive in order ;
④TCP Provide full duplex communication ,TCP Both ends are provided with sending buffer and receiving buffer , Used to temporarily store data for two-way communication ;
⑤ Byte stream oriented ;
Packet size limit 1460;
Socket Socket = (IP Address : Port number )
Network knowledge
IP Address
It is divided into network number and host number ,IP Address (IPADDR) And mask (NETMASK) Perform bitwise and binary , Such as IP:192.168.6.63, Mask 255.255.255.0, The bitwise and subsequent network numbers are 192.168.6, Host number 63;
gateway
And IP The address is in the same network segment , All packets in the LAN are delivered to the gateway , The gateway is responsible for sending to the external network , Play a connecting role ;
Basic protocol number port number
Ethernet protocol number :IP:0x0800,ARP:0x0806;
IP Agreement No :ICMP:1,TCP:6,UDP:17;
Port number :FTP:20 21,SSH:22,Telnet:23,SMTP:25,HTTP:80;
TCP/IP Connection process ( Reprint )
Three handshake process
The first handshake : When establishing a connection , The client sends syn package (syn=x) To the server , And enter SYN_SENT state , Wait for server to confirm ;SYN: Sync sequence number (Synchronize Sequence Numbers).
The second handshake : Server received syn package , Must confirm customer's SYN(ack=x+1), At the same time, I also send a SYN package (syn=y), namely SYN+ACK package , At this time, the server enters SYN_RECV state ;
The third handshake : Client receives server's SYN+ACK package , Send confirmation package to server ACK(ack=y+1), This package has been sent , Client and server access ESTABLISHED(TCP Successful connection ) state , Complete three handshakes .
Four waves
1) The client process sends the connection release message , And stop sending data . Release data message header ,FIN=1, Its serial number is seq=u( It is equal to the sequence number of the last byte of the previously transmitted data plus 1), here , Client access FIN-WAIT-1( Stop waiting 1) state . TCP Regulations ,FIN Even if the message segment does not carry data , Also need to consume a serial number .
2) The server receives the connection release message , Send confirmation message ,ACK=1,ack=u+1, And bring your own serial number seq=v, here , The server enters CLOSE-WAIT( Turn off waiting ) state .TCP The server informs the high-level application process , The client is released in the direction of the server , It's half closed , That is, the client has no data to send , But if the server sends data , The client still has to accept . It's going to last a while , That is the whole CLOSE-WAIT The duration of the State .
3) After the client receives the confirmation request from the server , here , The client enters FIN-WAIT-2( Stop waiting 2) state , Wait for the server to send the connection release message ( Before that, you need to accept the last data sent by the server ).
4) After the server sends the last data , Send the connection release message to the client ,FIN=1,ack=u+1, Because it's half closed , The server probably sent some more data , Suppose the serial number at this time is seq=w, here , The server is in LAST-ACK( Final confirmation ) state , Wait for the client to confirm .
5) After the client receives the connection release message from the server , Confirmation must be sent ,ACK=1,ack=w+1, And my serial number is seq=u+1, here , The client enters TIME-WAIT( Time waits ) state . Note that this time TCP The connection has not been released , Must go through 2∗∗MSL( Maximum segment life ) After , When the client cancels the corresponding TCB after , Only enter CLOSED state .
6) As long as the server receives the confirmation from the client , Enter immediately CLOSED state . Again , revoke TCB after , It's the end of this TCP Connect . You can see , End of server TCP The connection time is earlier than the client .
Frequently asked questions
【 problem 1】 Why three handshakes when connecting , It's four handshakes when it's closed ?
answer : Because when Server End receipt Client Terminal SYN After connecting the request message , It can be sent directly SYN+ACK message . among ACK Messages are used to answer ,SYN Messages are used to synchronize . But when you close the connection , When Server End receipt FIN When the message , It's not likely to shut down immediately SOCKET, So you can only reply one first ACK message , tell Client End ,“ You sent it FIN I received the message ”. Only when I Server All messages are sent , I can send FIN message , So we can't send . So it takes four steps to shake hands .
【 problem 2】 Why? TIME_WAIT Status needs to pass 2MSL( Maximum segment lifetime ) To return to CLOSE state ?
reason 1: In order to ensure Client The last one sent ACK Messages can reach Server, This ACK Message segments may be lost , So in LAST-ACK State of Server Can't receive the sent FIN+ACK Confirmation of message segment ,Server It will be retransmitted over time FIN+ACK Message segment , and Client You can be in 2MSL Received this retransmission in time FIN+ACK Message segment , next Client Retransmission confirmation , Restart 2MSL timer , Last Client and Server All of them enter into CLOSED state . If Client stay TIME-WAIT State does not wait for a period of time , It's sending out ACK Release connection immediately after message segment , Then you can't receive Server Retransmission FIN+ACK Message segment , Therefore, the confirmation segment will not be sent again , such ,Server You can't follow the normal steps to enter CLOSED state .
reason 2: prevent “ Invalid connection request message segment ” Appears in this connection ,Client After sending the last ACK After message segment , After another time 2MSL, It can make all message segments generated during the duration of this connection disappear from the network , In this way, the old connection request segment will not appear in the next new connection .
【 problem 3】 Why not connect with two handshakes ?
answer : The main purpose is to prevent the invalid connection request message from being suddenly sent to the server , So there's a mistake ;
Possible situation : Invalid connection request message segment ” In such a case :client The first connection request segment sent is not lost , But in a network node for a long time , So that it will not arrive until some time after the connection is released server. Originally, this is a message segment that has already failed . but server After receiving this invalid connection request message segment , I mistook it for client A new connection request issued again . So I went to client Send confirmation message segment , Agree to establish a connection . Suppose you don't use “ Three handshakes ”, So as long as server Send a confirmation , A new connection is established . Because now client No connection request was made , So I won't pay any attention to server The confirmation of , Nor to server send data . but server But think that a new transport connection has been established , And kept waiting client Send data . such ,server A lot of resources are wasted . use “ Three handshakes ” The method can prevent the above phenomenon . For example, the situation just now ,client No direction server To send out a confirmation .server Because no confirmation can be received , You know client No connection required .
【 problem 4】 If a connection has been established , But what to do if the client suddenly fails ?
answer :TCP There is also a survival timer , obviously , If the client fails , The server can't wait , Waste resources in vain . The server will reset this timer every time it receives data from the client , The time is usually set to two hours , If you haven't received any data from the client in two hours , The server will send a detection segment , After every 75 Send once per second . If you send it in a row 10 Detection messages still don't respond , The server thinks the client is down , Then close the connection .
边栏推荐
- Lua callinfo structure, stkid structure resolution
- Factory mode of "object creation" mode
- M1 pod install pod lint failure solution
- Compile and install lamp architecture of WordPress and discuz for multi virtual hosts based on fastcgi mode
- Tool notes - common custom tool classes (regular, random, etc.)
- 1414. minimum number of Fibonacci numbers with sum K
- 2000. reverse word prefix
- Programmer interview golden classic good question / interview question 01.05 Edit once
- SystemC:SC_ Thread and SC_ METHOD
- Redis data deletion policy in 2022
猜你喜欢
TestEngine with ID ‘junit-vintage‘ failed to discover tests
Alibaba cloud development board haas510 connects to the Internet of things platform -- Haas essay solicitation
Design of PLC intelligent slave station based on PROFIBUS DP protocol
Briefly describe the difference between CGI and fastcgi
Socket model of punctual atom stm32f429 core board
【mysql进阶】索引分类及索引优化方案(五)
Axi4 increase burst / wrap burst/ fix burst and narrow transfer
Des File Encryptor based on MFC framework
Go language functions as parameters of functions
阿里云开发板HaaS510响应UART串口指令
随机推荐
Write policy of cache
Summary of virtual box usage problems
Alibaba cloud development board haas510 connects to the Internet of things platform -- Haas essay solicitation
Binary tree traversal
【活动早知道】LiveVideoStack近期活动一览
Design of PLC intelligent slave station based on PROFIBUS DP protocol
初学者入门阿里云haas510开板式DTU(2.0版本)--510-AS
Leetcode 2176. 统计数组中相等且可以被整除的数对
Is Shell Scripting really a big technology?
TestEngine with ID ‘junit-vintage‘ failed to discover tests
PostgreSQL14安装使用教程
WinDbg preview debug analysis createtoolhelp32snapshot
Cmake basic tutorial - 02 b-hello-cmake
Player actual combat 16 xdecode class
OAuth2学习中的一些高频问题的QA
Getting started alicloud haas510 open board DTU (version 2.0) --510-as
2000. reverse word prefix
How to realize the bidding strategy that pays more attention to transformation in the company's operation Google sem
Axi4 increase burst / wrap burst/ fix burst and narrow transfer
Redis核心配置和高级数据类型