1

I'v got a simple setup:

Server (IP 10.0.0.33) listening on port 7770 using the command: $ netcat -lup 7770 And a client (IP 10.0.0.2) that communicates with the server using: $ nc -u 10.0.0.33 7770 < message to server> (more text)

After I enter the command at the client, I execute this command in another terminal on the client: $ lsof -i COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME nc 7 root 3u IPv4 197517 0t0 UDP 10.0.0.2:59621->10.0.0.33:7770

How does the lsof command display the UDP "connection"? Isn't UDP supposed to connectionless?

1 Answer 1

2

Yes, UDP is connectionless. It fires off it datagram, then it forgets about it.

The UDP in one host did not negotiate and create a connection with the UDP in the other host. One of the hosts could simply go away, and the other host would never know because there is no connection.

An application still needs to tell UDP to open a UDP port to send something, and it needs to tell UDP the destination port. That is what you are seeing, but that is not actually a connection the way TCP in one host negotiates with TCP in a different host. UDP does not negotiate or maintain a connection, it will simply send a datagram. Also, the application can close the UDP socket, and UDP simply forgets it, it doesn't negotiate closing a connection with UDP in the other host.

There is much more to a TCP connection than simply the addressing, even though a TCP connection is identified by the addressing. RFC 793, Transmission Control Protocol explains:

Connections:

The reliability and flow control mechanisms described above require that TCPs initialize and maintain certain status information for each data stream. The combination of this information, including sockets, sequence numbers, and window sizes, is called a connection. Each connection is uniquely specified by a pair of sockets identifying its two sides.

When two processes wish to communicate, their TCP's must first establish a connection (initialize the status information on each side). When their communication is complete, the connection is terminated or closed to free the resources for other uses.

Since connections must be established between unreliable hosts and over the unreliable internet communication system, a handshake mechanism with clock-based sequence numbers is used to avoid erroneous initialization of connections.


Host OSes are actually off-topic here, and how a host OS implements something like UDP is off-topic, although the protocol theory for UDP is on-topic.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.