客户端向服务器发出TCP连接请求后,是否可以在其端的另一个端口上收到服务器生成的回复

发布于 2024-12-27 18:43:54 字数 279 浏览 3 评论 0原文

当 TCP 客户端在服务器的侦听端口上请求 conn'n 时,服务器将接受它并创建一个用于与该客户端进行 conn'n 的新端口。此后,客户端将在这个新端口上与服务器进行通信。

如果上述陈述成立并且可能,服务器如何将新生成的端口传递给客户端。在回复 conn'n 请求时,从服务器到客户端的数据包将以哪个端口作为源端口(服务器的侦听端口或服务器为客户端生成的新端口)。 客户端会接受这个端口并使用还是会出错?我需要它来使用 lwip 堆栈在嵌入式系统中实现具有 2 个客户端和一个服务器的架构。

问候, 急诊科

When TCP client requests conn'n on server's listening port, server will accept it and create a new port meant for this conn'n with this client. Hence forth the client will communicate with server on this new port.

if the above statement is true and possible, how server conveys the newly generated port to client. In reply to the conn'n request the packet from server to client will have what port as source port (Server's listening port OR New port generated by server for client).
Will Client accept this port and take into use or it will give error ? I need this to implement an architecture having 2 clients and one server in an embedded system using lwip stack.

regards,
ED

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

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

发布评论

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

评论(2

李不 2025-01-03 18:43:54

服务器不创建新端口。它创建一个新的 TCP 连接,并将其回复数据包发送到客户端发送其连接请求的 IP 和端口。 (TCP 连接的每一端都有一个 IP 地址和端口。)

The server doesn't create a new port. It creates a new TCP connection and it sends its reply packets to the IP and port the client sent its connection request from. (A TCP connection has an IP address and port on each side.)

静若繁花 2025-01-03 18:43:54

当您连接到服务器时,您自己会获得一个端口号,该端口号是由系统分配给您的(除非您在连接之前绑定套接字)。当服务器的网络堆栈回复您的连接请求时,“源”端口是服务器的新端口号,消息的“目标”端口是您的端口。这就是客户端的网络堆栈如何知道服务器具有哪个端口的方式。

服务器上用于连接的新端口号无法由实际服务器程序设置或更改,服务器计算机上的网络堆栈只是获取可用的端口号。

编辑:您可能还想了解一下如何建立连接,又名三向握手。

When you connect to a server, you get a port number yourself, which is assigned to you by the system (unless you bind the socket before connecting). When the network stack of the server replies to your connection request, the "source" port is the new port number of the server, and the "destination" port of the message is your port. That's how the network stack on the client side knows what port the server has.

The new port number on the server used for your connection can not be set or changed by the actual server program, it's the network stack on the server machine that just grabs an available port number.

Edit: You might also want to read up a little on how connections are established, a.k.a. the three-way handshake.

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