User Datagram Protocol. Introduction UDP is a connectionless transport protocol, i.e. it doesn't guarantee either packet delivery or that packets arrive.

Slides:



Advertisements
Similar presentations
Socket UDP H. Fauconnier 1-1 M2-Internet Java. UDP H. Fauconnier M2-Internet Java 2.
Advertisements

Umut Girit  One of the core members of the Internet Protocol Suite, the set of network protocols used for the Internet. With UDP, computer.
UDP & TCP Where would we be without them!. UDP User Datagram Protocol.
UDP Datagrams and Sockets Instructors: Fu-Chiung Cheng ( 鄭福炯 ) Associate Professor Computer Science & Engineering Tatung University.
Copyright 1999, S.D. Personick. All Rights Reserved. Telecommunications Networking II Lecture 32 Transmission Control Protocol (TCP) Ref: Tanenbaum pp:
Jan Java Networking UDP Yangjun Chen Dept. Business Computing University of Winnipeg.
Socket Programming.
CSCE 515: Computer Network Programming Chin-Tser Huang University of South Carolina.
Prepared By E. Musa Alyaman1 User Datagram Protocol (UDP) Chapter 5.
1 Java Networking – Part I CS , Spring 2008/9.
1 L53 Networking (2). 2 OBJECTIVES In this chapter you will learn:  To understand Java networking with URLs, sockets and datagrams.  To implement Java.
Networking Support In Java 2 Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Java Socket Support Presentation by: Lijun Yuan Course Number: cs616.
Networking Support In Java Nelson Padua-Perez Bill Pugh Department of Computer Science University of Maryland, College Park.
2: Application Layer1 Socket Programming. 2: Application Layer2 Socket-programming using TCP Socket: a door between application process and end- end-transport.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 25 Networking.
1 Socket-based Client- Server Application Client-Server application architecture Choosing services – Connectionless atau Connection-oriented.
Networking Support In Java 2 Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Datagram Programming A datagram is an independent, self-contained message sent over the network whose arrival, arrival time, and content are not guaranteed.
WXES2106 Network Technology Semester /2005 Chapter 8 Intermediate TCP CCNA2: Module 10.
Process-to-Process Delivery:
TRANSPORT LAYER T.Najah Al-Subaie Kingdom of Saudi Arabia Prince Norah bint Abdul Rahman University College of Computer Since and Information System NET331.
Babak Esfandiari (based on slides by Qusay Mahmoud)
CS 352-Socket Programming & Threads Dept. of Computer Science Rutgers University (Thanks,this slides taken from er06/
CS4273: Distributed System Technologies and Programming I Lecture 5: Java Socket Programming.
Multicast Sockets What is a multicast socket?
TCP/IP: Basics1 User Datagram Protocol (UDP) Another protocol at transport layer is UDP. It is Connectionless protocol i.e. no need to establish & terminate.
IP and Errors IP Best Effort Datagrams can be: –Lost –Delayed –Duplicated –Delivered out of order –Corrupted.
 Socket  The combination of an IP address and a port number. (RFC 793 original TCP specification)  The name of the Berkeley-derived application programming.
6.1. Transport Control Protocol (TCP) It is the most widely used transport protocol in the world. Provides reliable end to end connection between two hosts.
VIII. UDP Datagrams and Sockets. The User Datagram Protocol (UDP) is an alternative protocol for sending data over IP that is very quick, but not reliable:
CS 424/524: Introduction to Java Programming Lecture 25 Spring 2002 Department of Computer Science University of Alabama Joel Jones.
Copyright 2002, S.D. Personick. All Rights Reserved.1 Telecommunications Networking II Topic 20 Transmission Control Protocol (TCP) Ref: Tanenbaum pp:
Socket Programming in Java CS587x Lecture 4 Department of Computer Science Iowa State University.
1 A TCP/IP Application Programming Perspective Chris Greenhalgh G53ACC.
1 Chapter 28 Networking. 2 Objectives F To comprehend socket-based communication in Java (§28.2). F To understand client/server computing (§28.2). F To.
Java Sockets Programming
L 2 - 1 3( 1/ 20) : Java Network Programming. The Socket API The previous contents describe client-server interaction that application programs use when.
Socket Programming Using JAVA Asma Shakil Semester 1, 2008/2009.
Sockets For Clients Instructors: Fu-Chiung Cheng ( 鄭福炯 ) Associate Professor Computer Science & Engineering Tatung University.
CSI 3125, Preliminaries, page 1 Networking. CSI 3125, Preliminaries, page 2 Inetaddress Class When establishing a connection across the Internet, addresses.
1 Netprog 2002 TCP/IP UDP/IP in Java Based on Java Network Programming and Distributed Computing.
Java Programming II Java Network (I) Java Programming II.
UDP & TCP Where would we be without them!. UDP User Datagram Protocol.
1 CSCD 330 Network Programming Fall 2013 Some Material in these slides from J.F Kurose and K.W. Ross All material copyright Lecture 8a Application.
IP1 The Underlying Technologies. What is inside the Internet? Or What are the key underlying technologies that make it work so successfully? –Packet Switching.
UDP User Datagram Protocol. About the UDP A commonly used transport protocol Does not guarantee either packet delivery or order The packets may travel.
McGraw-Hill Chapter 23 Process-to-Process Delivery: UDP, TCP Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
1 Socket-based Client- Server Application Client-Server application architecture Choosing services – Connectionless atau Connection-oriented.
Agenda Socket Programming The OSI reference Model The OSI protocol stack Sockets Ports Java classes for sockets Input stream and.
UDP Programming. Khoa CNTT – ĐH Nông Lâm TP. HCM 01/2007 2/86 Overview.
TCP/IP1 Address Resolution Protocol Internet uses IP address to recognize a computer. But IP address needs to be translated to physical address (NIC).
Client/Server Design Issues Based on Java Network Programming and Distributed Computing, Chapter 6 Also Online Java Tutorial, Sun.
Process-to-Process Delivery:
CSCE 515: Computer Network Programming Chin-Tser Huang University of South Carolina.
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 33 Networking.
Java.net CS-328 Dick Steflik.
Object-Orientated Analysis, Design and Programming
Socket-based Client-Server Application
Network Programming Introduction
Network Programming Introduction
Process-to-Process Delivery:
CSCD 330 Network Programming
CSCD 330 Network Programming
NETWORK PROGRAMMING CNET 441
Socket-based Client-Server Application
Process-to-Process Delivery: UDP, TCP
Computer Networks Protocols
Socket Programming with UDP
Based on Java Network Programming and Distributed Computing
Presentation transcript:

User Datagram Protocol

Introduction UDP is a connectionless transport protocol, i.e. it doesn't guarantee either packet delivery or that packets arrive in sequential order. With UDP, bytes of data are grouped together in discrete packets which are sent over the network.

Packets may travel along different paths depending on the state of the network. No two packets are guaranteed the same route. Each packet has a time-to-live (TTL) counter, which is updated when it is routed along to the next point in the network. When the timer expires, it will be discarded, and the recipient will not be notified.

If a packet does arrive, it will always arrive intact. Packets that are corrupt or only partially delivered are discarded.

Advantages of UDP UDP communication can be more efficient than guaranteed-delivery data streams. Unlike TCP streams, which establish a connection, UDP causes fewer overheads. Real-time applications that demand up-to- the-second or better performance may be candidates for UDP, as there are fewer delays due to error checking and flow control of TCP.

UDP sockets can receive data from more than one host machine. Some network protocols specify UDP as the transport mechanism.

Java Support for UDP Two classes are provided:  DatagramPacket class (java.net)  DatagramSocket class (java.net)

DatagramPacket Class A DatagramPacket object represents a data packet intended for transmission using UDP. It contains addressing information such as an IP address and a port. When a DatagramPacket is read from a UDP socket, the IP address/port of the packet represents the address/port of the sender.

When a DatagramPacket is used to send a UDP packet, the IP address/port represents the address/port of the recipient. DatagramPacket IP address (java.net.InetAddr) Port address (int) Packet data (byte[])

Creating a DatagramPacket Constructor to use for creating a DatagramPacket for receiving incoming UDP packets: DatagramPacket(byte[] buffer, int length) Example: DatagramPacket packet; packet = new DatagramPacket(new byte[256], 256);

Constructor to use for sending a DatagramPacket to a remote machine DatagramPacket(byte[] buffer, int length, InetAddress dest_addr, int dest_port) Example: DatagramPacket packet; InetAddress addr; addr = InetAddress.getByName(" "); packet = new DatagramPacket(new byte[128], 128,addr, 2000);

DatagramPacket Methods Refer p121.  InetAddress getAddress()  byte[] getData()  int getLength()  int getPort()  void setAddress(InetAddress addr)  void setData(byte[] buffer)  void setLength(int length)  void setPort(int port)

DatagramSocket Class The DatagramSocket class provides access to a UDP socket, which allows UDP packets to be sent and received. The same DatagramSocket can be used to receive as well as to send packets. read operations are blocking - i.e. the application will continue to wait until a packet arrives.

Each DatagramSocket binds to a port on the local machine. The port number need not match the port number of the remote machine. If the application is a UDP server, it will usually bind to a specific port number.

Creating a DatagramSocket Constructor to use for creating a client DatagramSocket : DatagramSocket() throws java.net.SocketException Example: DatagramSocket socket; try { socket = new DatagramSocket(); } catch (SocketException exception) { … }

Constructor to use for creating a server DatagramSocket : DatagramSocket(int port) throws java.net.SocketException Example: DatagramSocket socket; try { socket = new DatagramSocket(2000); } catch (SocketException exception) { … }

DatagramSocket Methods Refer p123.  void close()  void connect(InetAddress r_addr, int r_port)  void disconnect()  InetAddress getInetAddress()  int getPort()  InetAddress getLocalAddress()  int getLocalPort()  int getReceiveBufferSize() throws java.net.SocketException

 int getSendBufferSize() throws java.net.SocketException  int getSoTimeout() throws java.net.SocketException  void receive(DatagramPacket packet) throws java.io.IOException  void send(DatagramPacket packet) throws java.io.IOException  int setReceiveBufferSize(int length) throws java.net.SocketException  int setSendBufferSize(int length) throws java.net.SocketException  void setSoTimeout(int duration) throws java.net.SocketException

Listening for UDP Packets Before an application can read UDP packets, it must  bind a socket to a local UDP port using DatagramSocket  create a DatagramPacket that will contain the data.

Packet DatagramSocket DatagramPacket UDP application Reads packets Translates packets Into a DatagramPacket

The following code illustrates the process for reading UDP packets. DatagramPacket packet; DatagramSocket socket; packet = new DatagramPacket(new byte[256], 256); socket = new DatagramSocket(2000); boolean finished = false; while (!finished) { socket.receive(packet); // process the packet } socket.close();

Java I/O streams are usually used to access the contents of the byte array in a DatagramPacket. See example later. DatagramPacket IP address (java.net.InetAddr) Port address (int) Packet data (byte[]) ByteArrayInputStream DataInputStream UDP application

Sending UDP Packets When sending a packet, the application must create a DatagramPacket that will contain the data. The address and port information must also be set. When the packet is ready for transmission, the send method of DatagramSocket should be invoked.

Packet DatagramSocket DatagramPacket UDP application Binds to a UDP port Constructs packet Send DatagramPacket using DatagramSocket

The following code illustrates the process for sending UDP packets. DatagramPacket packet; DatagramSocket socket; packet = new DatagramPacket(new byte[256], 256); socket = new DatagramSocket(2000); packet.setAddress(…); packet.setPort(2000); boolean finished = false; while (!finished) { // write data to packet buffer socket.send(packet); … } socket.close();

User Datagram Protocol Example Run receiving application java PacketReceiveDemo Run sending application java PacketSendDemo

DatagramSocket PacketSendDemo ByteArrayOutputStream PrintStream DatagramPacket print(str) toByteArray() send(packet)

DatagramSocket PacketReceiveDemo ByteArrayInputStream DatagramPacket receive(packet) read() getData()

Building a UDP Client/Server Run echo server java EchoServer Run echo client java EchoClient

Algorithm for Echo Server 1. Create socket 2. Create an empty packet 3. Repeat the following forever 1. Wait for a packet 2. Send the packet back to sender

Algorithm for Echo Client 1. Create socket 2. Set timeout value for socket 3. Repeat the following ten times 1. Create the message to be sent 2. Create packet containing the message as well as the destination IP and the port 3. Send the packet through socket 4. Wait for packet from receiver through socket or timeout 5. if packet received 1. Create an input stream to access data in the packet 2. Use the input stream to read the data and then display it on the screen. 6. Sleep for a second

Overcoming UDP Limitations UDP limitations:  Lack of Guaranteed Delivery  Lack of Guaranteed Packet Sequencing  Lack of Flow Control

Lack of Guaranteed Delivery Packets sent via UDP may become lost in transit. UDP packets can also become damaged or lost. For some applications, the loss of individual packets may not have a noticeable effect (e.g. video streams). For other applications, loss of packets is not acceptable (e.g. file transfers).

If guaranteed delivery is required,  avoid packet-based communication, and use a more suitable transport mechanism (e.g. TCP).  send acknowledgement to sender after receiving packets.

Lack of Guaranteed Packet Sequencing Applications that require sequential access to data should include a sequence number in the contents of a datagram packet. This enables detection of duplicate packets and also missing packets.

Lack of Flow Control The technique of flow control is important to avoid flooding a system with more data than it can handle due to limited bandwidth. One technique of flow control is to limit the number of unacknowledged packets. E.g.: increase control when number of acknowledgement packets received is much less than the number of packets sent.