简体   繁体   中英

Could a local port be used to connect to multiple remote peers over UDP?

With connect(int socket, const struct sockaddr *address, socklen_t address_len); , according to 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.

Does that mean a local port could still be used to connect to several remote peers over UDP? Or is it that one local port could only be used to connect to one peer?

Thanks

If you call connect() on your UDP socket, then you can only use it to send and receive packets to/from the address you passed in to connect().

However, if you do not call connect() on the UDP socket, you can use sendto() and recvfrom() to send/receive packets to/from multiple destinations using just that one socket.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM