TCP/UDP 解复用的工作原理是什么?工作原理、复用、TCP、UDP

2023-09-08 09:15:19 作者:泪倾城

我有以下声明.

"在 TCP 中,接收方主机使用所有源 IP、源端口、目的 IP 和目的端口将数据报定向到适当的套接字.而在 UDP 中,接收方仅检查目的端口号来定向数据报."

"In TCP, the receiver host uses all of source IP, source port, destination IP and destination port to direct datagram to appropriate socket. While in UDP, the receiver only checks destination port number to direct the datagram. "

以上说法是真的吗?

如果是,是否意味着在 TCP 中同一个端口可以在一个进程中用于多个套接字,而在 UDP 中,在一个进程中的一个端口上只能使用一个套接字?不同进程中的套接字呢?多个进程可以在 TCP/UDP 中使用同一个端口吗?(编程语言:C/C++/Java)

If yes, does it mean that in TCP the same port can be used for multiple socket in one process, while in UDP only one socket can use on a port in one process? What about sockets in different processes? Can multiple processes use the same port in TCP/UDP? (in programming language: C/C++/Java)

如果不是,为什么?

推荐答案

"在 TCP 中,接收方主机使用所有源 IP、源端口、目的 IP 和目的端口将数据报定向到适当的套接字.而在 UDP 中,接收方仅检查目的端口号来定向数据报."

"In TCP, the receiver host uses all of source IP, source port, destination IP and destination port to direct datagram to appropriate socket. While in UDP, the receiver only checks destination port number to direct the datagram. "

以上说法属实吗?

是的.

如果是,是不是意味着在TCP中同一个端口可以在一个进程中用于多个socket,

6TCP和UDP

If yes, does it mean that in TCP the same port can be used for multiple socket in one process,

是的,在某些情况下.

而在 UDP 中,一个进程中的一个端口只能使用一个套接字?

while in UDP only one socket can use on a port in one process?

不,见下文.

不同进程中的套接字呢?多个进程可以在 TCP/UDP 中使用同一个端口吗?(编程语言:C/C++/Java)

What about sockets in different processes? Can multiple processes use the same port in TCP/UDP? (in programming language: C/C++/Java)

在某些情况下,是的.UDP 端口必须被所有想要共享它的进程指定为可重用.一个 TCP 端口只能被绑定到不同接口的套接字重用:没有共享.

Under some circumstances, yes. A UDP port has to be designated as reusable by all processes that want to share it. A TCP port can only be reused by sockets bound to different interfaces: there is no sharing.