1
votes

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

1

1 Answers

1
votes

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.