是否可以使用本地端口通过 UDP 连接到多个远程对等点?
Could a local port be used to connect to multiple remote peers over UDP?
与connect(int socket, const struct sockaddr *address, socklen_t address_len);
,根据man 2 connect
:
The parameter socket is a socket. If it is of type SOCK_DGRAM, this call specifies the peer with which
the socket is to be associated; this address is that to which
datagrams are to be sent, and the only address from which datagrams
are to be received.
这是否意味着本地端口仍可用于通过 UDP 连接到多个远程对等点?还是一个本地端口只能用于连接一个对端?
谢谢
如果您在 UDP 套接字上调用 connect(),那么您只能使用它来发送和接收数据包to/from您传递给 connect() 的地址。
但是,如果您不在 UDP 套接字上调用 connect(),则可以使用 sendto() 和 recvfrom() 来 send/receive 数据包 to/from 仅使用一个套接字的多个目的地。
与connect(int socket, const struct sockaddr *address, socklen_t address_len);
,根据man 2 connect
:
The parameter socket is a socket. If it is of type SOCK_DGRAM, this call specifies the peer with which the socket is to be associated; this address is that to which datagrams are to be sent, and the only address from which datagrams are to be received.
这是否意味着本地端口仍可用于通过 UDP 连接到多个远程对等点?还是一个本地端口只能用于连接一个对端?
谢谢
如果您在 UDP 套接字上调用 connect(),那么您只能使用它来发送和接收数据包to/from您传递给 connect() 的地址。
但是,如果您不在 UDP 套接字上调用 connect(),则可以使用 sendto() 和 recvfrom() 来 send/receive 数据包 to/from 仅使用一个套接字的多个目的地。