UDP is connectionless, but it is still based on bound ports. The receiver must call sendto()
, connect()
, or bind()
to establish a local bound port so the OS knows which port to allow inbound data on, and to establish the port that the sender needs to send data to. If the receiver is the first party to send a packet, then the bind can be implicit, but if the receiver is not the first party then a bind must be done explicitly.
If the receiver did not bind a local port, the port would not be opened at worse, or would be randomly chosen by the OS at best. Either way, the sender would have no hope of knowing which port to send data to, unless the receiver told the sender through external means. Even then, in order for the receiver to discover a randomly assigned port, it would have to query the socket, but an unbound socket cannot be queried. So the receiver has to perform a local bind one way or the other.