User Datagram Protocol (UDP)
UDP service: • “no frills,” “bare bones” extension of best-effort IP Computer Networks • “best effort” service, UDP segments may be: • lost • delivered out of order to app • connectionless: • no handshaking between UDP sender and receiver Lecture 25: • each UDP segment handled independently of others UDP Socket
UDP [RFC 768] UDP Socket 32 bits UDP socket identified by the tuple: src port # dst port # length, in bytes, of
Data Transmission No Connection No “connection” between sender and receiver • sender explicitly attaches IP address and port# of destination to each packet, by using sendto() instead of send() • send() can still be used if server’s address and port# have been “registered” with kernel using connect() • if receiver uses recvfrom() it can extract IP address and port# of sender from received packet • if these are not needed, recv() may be used instead Transmitted data may be delivered out of order, or not delivered at all
Stevens Socket Addresses Data Transmission Somewhere in the socket structure: UDP packets have boundaries, not forming a byte-stream as in TCP, so recv() retrieves one message at a time,
i.e., no need to call TCP Server: UDP Server: recv() in a loop • call to recv() returns
the whole packet
• cannot retrieve only parts of a packet TCP Client: UDP Client: • to inspect a packet call recv() with flags=MSG_PEEK • same for recvfrom() and recvmsg() Stevens
Socket Buffers Lab5 Demo
When receiver’s socket receive buffer is full, incoming Best-effort netimg with no flow-control and no UDP packets will simply be dropped error-control Learn how to set send and receive buffer sizes If sender’s socket send buffer is smaller than the size of Play with different receive buffer sizes and observe UDP data passed to send(), send() returns -1 and effect of lack of flow control the system global variable errno is set to EMSGSIZE Play with different drop rates and observe effect of The APIs getsockopt() and setsockopt() are used lack of error control to query and set socket options, including the Learn how to send and receive large data buffer SO_RCVBUF and SO_SNDBUF options using gather write (sendmsg()) and scatter read (recvmsg()) Output data is gathered How to Send a Large File Gather Write from multiple buffers Error recovery and correction both require send this i/o vector associating data with sequence number (sqn) sqnsqnsqn7K1K2K3K4K8K5K6K0 reused! How to attach sequence numbers to chunks of data to be sent (assuming 1K segment)? to be sent on network: 0 1K 2K 3K sqn1K sqn1K 4K 5K 6K 7K sqn5K sqn0 sqn5K sqn0 FILE IN MEMORY FILE IN MEMORY sqn7K 8K sqn7K sqn6K sqn8K sqn6K sqn8K sqn2K sqn4K sqn3K sqn2K sqn4K sqn3K
Input data is scattered Scatter Read into multiple buffers Out-of-Order Packets
receive into here i/o vector receive into here i/o vector sqnsqnsqn1K2K3K4K5K6K7K8K0 reused! sqnsqnsqn2K3K5K6K7K8K4K0 reused!
received from network: received from network: sqn1K sqn5K sqn0 sqn5K sqn0 MEMORY BUFFER MEMORY BUFFER sqn7K sqn7K sqn6K sqn8K sqn6K sqn8K
sqn2K sqn2K sqn4K sqn3K sqn4K sqn3K TCP can also use sendto(), recvfrom(), sendmsg(), Data Scatter/Gather and recvmsg() Lab5: Sequence Number
The socket APIs for scatter-gather I/O are Sequence number is per byte, not per packet recvmsg(sd, msg, flags) and sendmsg(sd, msg, flags) The sequence number attached to a packet is the
used to identify sequence number of its first byte destination when sending The sequence number of a byte is its byte offset from the start of image buffer pointer to a sqn vector of This enables out-of-order data to be placed in its pointers to data buffers right position in the image buffer
where sender information is stored when receiving
[Stevens]
Lab5: Interoperability Testing
Home firewall may block UDP packets
Use “ssh -Y” to test client on CAEN eecs489 hosts if UDP blocked by home firewall • on Windows, use MobaXterm or similar tools that supports X forwarding
VNC may have OpenGL compatibility issues and is slower