Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
使用 netstat 我在我的列表中找到了这个
TCP 127.0.0.1:9832 My-PC:9832 ESTABLISHED
我的问题是我的本地端口如何传出并连接到同一个 TCP 端口?
这破坏了我的代码,因为我正在监听端口 9832。我收到权限错误。在此代码起作用之前,我需要丢失 Firefox 并重新打开我的所有选项卡。我想的另一个问题是是否有一个范围应该用于收听并且不会用作传出连接?
我很困惑。
对传出连接和侦听使用相同的端口号是完全有效的。如果您要连接到自己的计算机,那么您将获得如您所展示的 netstat 输出。
TCP 连接由 4 元组 (source-ip, source-port, dest-ip, dest-port) 标识,因此没有什么说 source-port 不能与 dest-port 相同。
也许您正在绑定到客户端代码中的特定端口?通常您只需要绑定到服务器代码的特定端口。
您关于必须关闭 Firefox 的问题无疑与此无关。