accept()
is for TCP. It has nothing to do with UDP.connect()
in UDP doesn’t do anything to the other end, it just conditions the local API to know who you are sending to and receiving from.If you don’t already know that, or don’t care, or want to send to multiple destinations with the same socket, you don’t use
connect()
, you usesendto()
instead. Similarly for receiving.Consider a UDP server for example. It would call
recvfrom(),
so it would get the source address information, process the request, create the response, and send it to that address viasendto().
Noconnect()
involved anywhere, ergo not possible to use eithersend()
orrecv().
It is only necessary to
bind()
a server, because the clients need a fixed port number to send to. A client needn’tbind()
at all: an automatic bind() will take place on the firstsend()/sendto()/recv()/recvfrom()
using a system-assigned local port number.