Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tcp的学习 #41

Open
YBFACC opened this issue Dec 11, 2020 · 0 comments
Open

tcp的学习 #41

YBFACC opened this issue Dec 11, 2020 · 0 comments
Labels

Comments

@YBFACC
Copy link
Owner

YBFACC commented Dec 11, 2020

tcp的学习

在本地或者服务器上使用node创建http服务器,在本地发起请求并使用wireshark来进行抓包分析。

tcp报文首部格式

以下两幅中、英文图对比观看,对抓到的数据可以轻松理解。

1

2

以下是使用wireshark抓包一次连接。

12-11-1

Seq、Ack这些值不是从0开始,实际上是由算法产生的。只是软件为了更加直观帮我们从0算起。

Flags

全部的Flags标示:

  • URG:是紧急数据,应尽快传送
  • ACK:确认号有效
  • PUSH:尽快交付,不需要等待缓存填满
  • RST:连接出现严重差错,释放连接再重新建立
  • SYN:连接请求或连接接受
  • FIN:数据发送完毕,要求释放连接

这些标示是由8个位来控制的。Flags代表这个tcp包的作用。

4

3次握手

5

客户端第1次发送请求时,seq根据自身算法得到。SYN表示请求连接

服务端第1次发送请求时,seq根据自身算法得到,ack=客户端seq+1。SYN表示接受请求,ACK表示确认号有效。

客户端第2次发送请求时,seq=服务端ack,ack=服务端seq+1。ACK表示确认号有效。

PS:虽然2个seq都显示为0,但是其真实值并不相同。

5-1

5-2

4次挥手🙋‍♂️

6

a端第1次,传输结束,要求释放连接。ACK表示确认号有效。FIN表示数据传送完毕,要求释放连接。

b端第1次,数据进行传输。ACK表示确认号有效。

b第2次,传输结束,已准备断开。ACK表示确认号有效。FIN数据传送完毕,要求释放连接。

a第2次,确认断开。ACK表示确认号有效。

7

PS:抓包时发现:首先发送FIN的不一定是客户端,服务端也可以。

3次挥手

10

假设客户端发起FIN。服务端也没有数据需要传输,服务端可以直接返回FIN,将2次回复变成1次。

参考

实战!我用 Wireshark 让你“看见“ TCP

wireshark分析TCP连接和关闭

图1、5、6 来自《第5 版计算机网络原理》课件

图2 https://www.cnblogs.com/lshs/p/6038458.html

@YBFACC YBFACC added the Http label Dec 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant