wireshark抓node请求问题,随机端口怎么产生的?
做的事情很简单,但是不知道怎么解释抓的包,求大佬指点下起个服务在3001端口
const Koa = require('koa');
const app = new Koa();
const axios = require('axios')
app.use(async ctx => {
if(ctx.path==='/'){
ctx.body = '1'
const res = await axios.get('http://localhost:3005')
console.log(res.data)
ctx.body = res.data
}
});
app.listen(3001);
再起个服务在3005端口
const Koa = require('koa');
const app = new Koa();
app.use(async ctx => {
ctx.body = 'Hello World from 3005';
});
app.listen(3005);
chrome浏览器去请求loacalhost:3001,返回Hello World from 3005对这个过程进行抓包,大体过程能看懂,但是还是有点问题 红框1,2,3三个分别代表啥东西红框1为什么不是127.0.0.1红框2是浏览器那个页签进程随机产生的一个端口吗。和80端口有啥联系没有红框3为什么不是3001 它是什么,怎么产生的
求大佬细说一下
回复
1个回答

test
2024-07-13
1: 这个是 ipv6 版得 127.0.0.1 。
2: 是的,一个随机端口,与 80 没有任何关系
3: 这个另一个随机端口。与 3001 无关。当你主动连接一个端口的时候,就会使用一个随机端口建立这个连接。
回复

适合作为回答的
- 经过验证的有效解决办法
- 自己的经验指引,对解决问题有帮助
- 遵循 Markdown 语法排版,代码语义正确
不该作为回答的
- 询问内容细节或回复楼层
- 与题目无关的内容
- “赞”“顶”“同问”“看手册”“解决了没”等毫无意义的内容