关于TCP/IP端口绑定的问题

发布于 2024-08-19 09:45:45 字数 83 浏览 5 评论 0原文

我想知道服务器应用程序是否总是在同一端口上应答?我在某处读到,为了继续监听“监听”端口,服务器将使用不同的端口。有人可以向我提供更多详细信息吗? 谢谢!

I would like to know whether a server application will always answer on the same port? I have read somewhere that in order to keep listening on the "listening" port, the server will use different port. Could anybody provide me with more details?
Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

嗼ふ静 2024-08-26 09:45:45

如果您在特定端口上与服务器建立 TCP 连接,则该 TCP 连接将继续使用服务器端的同一端口。

TCP 连接是在一侧的 (address1, port1) 对和另一侧的 (address2, port2) 对之间建立的 - 所有这四个值都是在 TCP 连接的生命周期内固定。

这不会阻止服务器在接受连接后侦听端口 - 因为它可以根据(地址,端口)区分已建立连接和新连接的任何数据包客户端使用的对。

例如,Oracle 服务器的这个 netstat 输出显示它正在侦听端口 1521,并且几个已建立的连接也使用该端口:

Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address               Foreign Address             State
tcp        0      0 0.0.0.0:1521                0.0.0.0:*                   LISTEN
tcp        0      0 127.0.0.1:1521              127.0.0.1:32776             ESTABLISHED
tcp        0      0 192.168.9.126:1521          192.168.9.124:32798         ESTABLISHED
tcp        0      0 192.168.9.126:1521          192.168.9.124:32823         ESTABLISHED
tcp        0      0 192.168.9.126:1521          192.168.9.124:32822         ESTABLISHED
tcp        0      0 192.168.9.126:1521          192.168.9.124:32821         ESTABLISHED
tcp        0      0 192.168.9.126:1521          192.168.9.124:32820         ESTABLISHED
tcp        0      0 192.168.9.126:1521          192.168.9.124:32819         ESTABLISHED
tcp        0      0 192.168.9.126:1521          192.168.9.124:32818         ESTABLISHED
tcp        0      0 127.0.0.1:1521              127.0.0.1:30536             ESTABLISHED
tcp        0      0 192.168.9.126:1521          192.168.9.124:36969         ESTABLISHED
tcp        0      0 127.0.0.1:32776             127.0.0.1:1521              ESTABLISHED
tcp        0      0 127.0.0.1:30536             127.0.0.1:1521              ESTABLISHED
tcp        0      0 192.168.9.126:1521          192.168.9.124:37786         ESTABLISHED
tcp        0      0 192.168.9.126:1521          192.168.9.124:37035         ESTABLISHED
tcp        0      0 192.168.9.126:1521          192.168.9.124:37034         ESTABLISHED
tcp        0      0 192.168.9.126:1521          192.168.9.124:33018         ESTABLISHED

If you make a TCP connection to a server on a particular port, that TCP connection will continue to use the same port on the server side.

A TCP connection is established between an (address1, port1) pair on one side and an (address2, port2) pair on the other side - and all four of these values are fixed over the life of the TCP connection.

This does not stop the server from listening on the port after it has accepted a connection - because it can differentiate between any packets for the established connection(s) and new connections based on the (address, port) pair used by the client.

For example, this netstat output from an Oracle server shows it listening on port 1521, and several established connections also using that port:

Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address               Foreign Address             State
tcp        0      0 0.0.0.0:1521                0.0.0.0:*                   LISTEN
tcp        0      0 127.0.0.1:1521              127.0.0.1:32776             ESTABLISHED
tcp        0      0 192.168.9.126:1521          192.168.9.124:32798         ESTABLISHED
tcp        0      0 192.168.9.126:1521          192.168.9.124:32823         ESTABLISHED
tcp        0      0 192.168.9.126:1521          192.168.9.124:32822         ESTABLISHED
tcp        0      0 192.168.9.126:1521          192.168.9.124:32821         ESTABLISHED
tcp        0      0 192.168.9.126:1521          192.168.9.124:32820         ESTABLISHED
tcp        0      0 192.168.9.126:1521          192.168.9.124:32819         ESTABLISHED
tcp        0      0 192.168.9.126:1521          192.168.9.124:32818         ESTABLISHED
tcp        0      0 127.0.0.1:1521              127.0.0.1:30536             ESTABLISHED
tcp        0      0 192.168.9.126:1521          192.168.9.124:36969         ESTABLISHED
tcp        0      0 127.0.0.1:32776             127.0.0.1:1521              ESTABLISHED
tcp        0      0 127.0.0.1:30536             127.0.0.1:1521              ESTABLISHED
tcp        0      0 192.168.9.126:1521          192.168.9.124:37786         ESTABLISHED
tcp        0      0 192.168.9.126:1521          192.168.9.124:37035         ESTABLISHED
tcp        0      0 192.168.9.126:1521          192.168.9.124:37034         ESTABLISHED
tcp        0      0 192.168.9.126:1521          192.168.9.124:33018         ESTABLISHED
画中仙 2024-08-26 09:45:45

作为 TCP 握手过程的一部分,在另一个端口上建立通信通道。源和目标“端口”号对应于 TCP 数据包标头中的 16 位字段。一旦建立通道,通信就会在该端口上进行,并在标头字段中包含适当的源端口和目标端口值。

初始连接到服务器上的监听端口;此后,该进程在分配的新端口上建立 TCP 连接,并在这些端口上进行进一步的通信。

As a part of the TCP handshaking process, a communication channel is established on another port. The source and destination 'port' numbers correspond to 16 bit fields in the TCP packet header. Once the channel is established, the communication takes place on that port, with the appropriate source and destination port values in the fields on the header.

The initial connection is made to the listening port on the server; after this, the process establishes a TCP connection on the new ports assigned and further communication takes place on those ports.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文