UDP "Connection" Basics
What is UDP
In many aspects, the User Datagram Protocol (UDP) is the opposite of TCP. Whereas TCP provides a reliable, stream-oriented transport, UDP offers a way to send data as separate packets or "datagrams." This is similar to "paging" (as in, sending a message with a "pager" — remember those?). What is sent is a packet containing some data. There is no guarantee that the other side will receive the packet and the sender won't know whether the packet was received or not.
Each UDP datagram lives its own life and you are responsible for dividing your data into chunks of reasonable size and sending it in separate datagrams. There is no connection establishment or termination on UDP — the datagram can be sent instantly, without any preparation.
Unlike TCP, UDP is not point-to-point. For example, several hosts can send datagrams to one socket of your device — and all of them can be accepted — a situation that is impossible with TCP. There is also an option to broadcast the datagram to all hosts connected to the same network segment — something that is also impossible with TCP.
And Now to UDP "connections"...
That said, it should come as a bit of a surprise that we will now turn 180 degrees and start talking about UDP "connections." Didn't we just say that there is no such thing? Well, yes and no. On the physical network there is, indeed, no such thing. However, on our sock. object level we have deliberately made UDP communications look more like TCP connections. And, since the UDP "connection" is nothing more than the sock. object's abstraction, we use the word "connection" in quotation marks.
We consider an active open to have been performed when our host has sent the first UDP datagram to the destination. A passive open is when we have received the first incoming UDP datagram from another host (provided that this datagram was accepted — more on that in Accepting Incoming Connections).
There is no graceful disconnect for UDP connections. The connection can only be discarded (our host "forgets" about it). The UDP connection can also time out.