客户端如何知道子 TCP 进程正在使用的临时端口?

How does the client know the ephemeral port being used by the child TCP process?

在阅读 TCP 的工作原理时,我读了很多书,其中提到在 listen() 之后,当客户端连接到服务器时,应该调用 accept()套接字程序员接受来自客户端的连接。父 TCP 服务器进程(侦听端口,比方说,80)然后调用 fork() 并创建一个子进程,该子进程将继续与客户端通信。子进程显然必须绑定到另一个临时端口才能与客户端通信。我的问题是,一旦子进程被分叉,客户端将如何知道将数据发送到哪个端口以便进行通信?侦听端口 80 的父 TCP 进程是否将其传送给客户端?

Hiw does the client know the ephemeral port being used by the child TCP process?

没有要知道的临时端口。客户端只是继续使用它连接到的相同目标端口。

The child process will obviously have to bind to another ephemeral port to communicate with the client.

没有。客户端进程继承accepted socket,与监听socket绑定在同一个本地端口。

My question is how will the client know which port to send the data to in order to communicate once the child process is forked?

它通过与其连接的同一端口进行通信。

Does the parent TCP process listening on port 80 convey it to the client?

客户端通过FD继承机制继承socket