html5-img
1 / 18

UDP: User Datagram Protocol

UDP: User Datagram Protocol. “bare bones”, “best effort” transport protocol connectionless: no handshaking between UDP sender, receiver before packets start being exchanged each UDP segment handled independently of others Just provides multiplexing/demultiplexing. Pros:

iolani
Télécharger la présentation

UDP: User Datagram Protocol

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. UDP: User Datagram Protocol

  2. “bare bones”, “best effort” transport protocol connectionless: no handshaking between UDP sender, receiver before packets start being exchanged each UDP segment handled independently of others Just provides multiplexing/demultiplexing Pros: No connection establishment No delay to start sending/receiving packets Simple no connection state at sender, receiver Small segment header Just 8 bytes of header Cons: “best effort” transport service means, UDP segments may be: lost delivered out of order to app no congestion control: UDP can blast away as fast as desired UDP: User Datagram Protocol [RFC 768]

  3. often used for streaming multimedia apps loss tolerant rate sensitive other UDP uses DNS SNMP reliable transfer over UDP: add reliability at application layer application-specific error recovery! UDP more Used for Mux/Demux 32 bits source port # dest port # Length, in bytes of UDP segment, including header checksum length Application data (message) UDP segment format

  4. Create sockets with port numbers: DatagramSocket mySocket1 = new DatagramSocket(6428); DatagramSocket mySocket2 = new DatagramSocket(4567); UDP socket identified by two-tuple: (dest IP address, dest port number) When host receives UDP segment: checks destination port number in segment directs UDP segment to socket with that port number IP datagrams with different source IP addresses and/or source port numbers directed to same socket UDP Demultiplexing

  5. P P1 P P SP: 6428 SP: 5775 SP: 6428 DP: 9157 DP: 5775 DP: 6428 UDP Demultiplexing Example DatagramSocket serverSocket = new DatagramSocket(6428); SP: 9157 client IP: A Client IP:B server IP: C DP: 6428 Source Port (SP) provides “return address”: Identifies the process at the other end of the line

  6. Sender: treat segment contents as sequence of 16-bit integers checksum: addition (1’s complement sum) of segment contents sender puts checksum value into UDP checksum field Receiver: compute checksum of received segment check if computed checksum equals checksum field value: NO - error detected YES - no error detected. But maybe errors nonetheless? Reordered bytes Why checksum at UDP if LL provides error checking? IP is supposed to run over ANY LL, so UDP does its own error checking UDP checksum Goal: detect “errors” (e.g., flipped bits) in transmitted segment

  7. TCP UDP IP LL PL TCP UDP IP LL PL TCP UDP IP LL PL Socket Layer Socket Layer Socket Layer How to program using the UDP? • Socket Layer: • Programmer’s API to the protocol stack • Typical network app has two pieces: client and server • Server: Passive entity.Provides service to clients • e.g., Web server responds with the requested Web page • Client: initiates contact with server (“speaks first”) • typically requests service from server, e.g., Web Browser

  8. Socket Creation • mySock = socket(family, type, protocol); • UDP/TCP/IP-specific sockets • Socket reference • File (socket) descriptor in UNIX • Socket handle in WinSock

  9. Client Create a UDP socket Communicate (send/receive messages) When done, close the socket Server Create a UDP socket Assign a port to socket Communicate (receive/send messages) When done, close the socket UDP Client/Server Interaction Server starts by getting ready to receive client messages…

  10. Client Create a UDP socket Communicate (send/receive messages) When done, close the socket Server Create a UDP socket Assign a port to socket Communicate (receive/send messages) When done, close the socket UDP Client/Server Interaction /* Create socket for incoming messages */ if ((servSock = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) Error("socket() failed");

  11. Client Create a UDP socket Communicate (send/receive messages) When done, close the socket Server Create a UDP socket Assign a port to socket Communicate (receive/send messages) When done, close the socket UDP Client/Server Interaction ServAddr.sin_family = PF_INET; /* Internet address family */ ServAddr.sin_addr.s_addr = htonl(INADDR_ANY); /* Any incoming interface */ ServAddr.sin_port = htons(20000); /* Local port 20000 */ if (bind(servSock, (struct sockaddr *) &ServAddr, sizeof(ServAddr)) < 0) Error("bind() failed");

  12. Specifying Addresses • struct sockaddr { unsigned short sa_family; /* Address family (e.g., PF_INET) */ char sa_data[14]; /* Protocol-specific address information */ }; • struct sockaddr_in { unsigned short sin_family; /* Internet protocol (PF_INET) */ unsigned short sin_port; /* Port (16-bits) */ struct in_addr sin_addr; /* Internet address (32-bits) */ char sin_zero[8]; /* Not used */ }; struct in_addr { unsigned long s_addr; /* Internet address (32-bits) */ }; Generic IP Specific

  13. Client Create a UDP socket Communicate (send/receive messages) When done, close the socket Server Create a UDP socket Assign a port to socket Communicate (receive/send messages) When done, close the socket UDP Client/Server Interaction struct sockaddr_in peer; int peerSize = sizeof(peer); char buffer[65536]; recvfrom(servSock, buffer, 65536, 0, (struct sockaddr *)&peer, &peerSize);

  14. Client Create a UDP socket Communicate (send/receive messages) When done, close the socket Server Create a UDP socket Assign a port to socket Communicate (receive/send messages) When done, close the socket UDP Client/Server Interaction Server is now blocked waiting for a message from a client

  15. Client Create a UDP socket Communicate (send/receive messages) When done, close the socket Server Create a UDP socket Assign a port to socket Communicate (receive/send messages) When done, close the socket UDP Client/Server Interaction Later, a client decides to talk to the server…

  16. Client Create a UDP socket Communicate (send/receive messages) When done, close the socket Server Create a UDP socket Assign a port to socket Communicate (receive/send messages) When done, close the socket UDP Client/Server Interaction /* Create socket for outgoing messages */ if ((clientSock = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) Error("socket() failed");

  17. Client Create a UDP socket Communicate (send/receive messages) When done, close the socket Server Create a UDP socket Assign a port to socket Communicate (receive/send messages) When done, close the socket UDP Client/Server Interaction // Initialize server’s address and port struct sockaddr_in server; server.sin_family = AF_INET; server.sin_addr.s_addr = inet_addr(“10.10.100.37”); server.sin_port = htons(20000); // Send it to the server sendto(clientSock, buffer, msgSize, 0, (struct sockaddr *)&server, sizeof(server));

  18. Client Create a UDP socket Communicate (send/receive messages) When done, close the socket Server Create a UDP socket Assign a port to socket Communicate (receive/send messages) When done, close the socket UDP Client/Server Interaction close(clientSock); close(serverSock);

More Related