SlideShare a Scribd company logo
1 of 18
Download to read offline
CHAPTER 3 :
User Datagram Protocol (UDP)
By :
Mr. Asyran Zarizi Bin Abdullah
User Datagram Protocol
• It’s a connection-less oriented protocol
• Simpler and less overhead compared to TCP
• Two important classes provided by Java API
under java.net
– DatagramSocket
• Class that support data transmission between sender
and receiver
– DatagramPacket
• Class that support data packet formation
Layman Terms for UDP
Java.net API
• Socket in JAVA will divide by 3 type :
– Socket client for TCP (stream)
• Java.net.Socket
– Socket server for TCP (stream)
• Java.net.ServerSocket
– Socket server for UDP
• Java.net.DatagramSocket
java.net.DatagramSocket class
• Class that use to send and receive DatagramPacket
from or to network
• Datagram is an information but no guarantee of its
content, arrival queue and arrival time.
Constructor
1) DatagramSocket (int port)
2) DatagramSocket(int port, InetAddress inet)
3) DatagramSocket()
Sample Syntax
java.net.DatagramPacket class
• Class use to represent a packet information (array
byte)
• Message that can be sent or received and can
arrived in any order.
Constructor
1) DatagramPacket(byte[], buf, int length)
2) DatagramPacket(byte[] buf, int length, InetAddress
address, int port)
Sample Syntax
Methods
• getData() : use to take an data information
• getLenght() : use to take datagram length
• getAddress() : use to take ip address information
• getPort() : use to take port address information
• Send(DatagramPacket data) : to send
DatagramPacket to host and port destination
• Receive(DatagramPacket data) : to block
execution until receive 1 complete packet
UDP Socket Structure
Did you remember
About previous lab (MySend)
And (MyReceiver)?
Example :
UDP vs TCP
User Datagram Protocol (UDP) Transmission Control Protocol (TCP)
Connectionless Oriented Connection-Oriented
Provide datagram services Provide stream services
No flow control, sequencing, and
error recovery.
Handles flow control, sequencing,
and error recovery.
Handles designation among
processes in the same host by means
of service port numbers.
Handles designation among
processes in the same host by means
of service port numbers.
There is a comparison between UDP and TCP
Datagram Socket
SERVER
1. Create a DatagramSocket object
– DatagramSocket dgramSocket = new
DatagramSocket(1234);
2. Create a buffer for incoming datagrams
– byte[] buffer = new byte[256];
3. Create a DatagramPacket object for the incoming
datagram
– DatagramPacket inPacket = new
DatagramPacket(buffer,buffer.length);
4. Accept an incoming datagram
– dgramSocket.receive(inPacket)
Datagram Socket
SERVER
5. Accept the sender’s address and port from the packet
– InetAddress clientAddress = inPacket.getAddress();
– int clientPort = inPacket.getPort();
6. Retrieve the data from the buffer
– string message = new String(inPacket.getData(), 0,
inPacket.getLength());
7. Create the response datagram
– DatagramPacket outPacket = new
DatagramPacket(response.getBytes()
, response.length(), clientAddress, clientPort);
8. Send the response datagram
– dgramSocket.send(outPacket)
9. Close the DatagramSocket: dgram.close();
Datagram Packet
CLIENT
1. Create a DatagramSocket object
– DatagramSocket dgramSocket = new
DatagramSocket;
2. Create the outgoing datagram
– DatagramPacket outPacket = new
DatagramPacket(message.getBytes(),
message.length(),host, port);
3. Send the datagram message
– dgramSocket.send(outPacket)
4. Create a buffer for incoming datagrams
– byte[] buffer = new byte[256];
Datagram Packet
CLIENT
5. Create a DatagramPacket object for the incoming
datagram
– DatagramPacket inPacket = new DatagramPacket(buffer,
buffer.length);
6. Accept an incoming datagram
– dgramSocket.receive(inPacket)
7. Retrieve the data from the buffer
– string response = new String(inPacket.getData(), 0,
inPacket.getLength());
8. Close the DatagramSocket:
– dgram.close();
MulticastSocket
• A class that use connection-less oriented
protocol to connect multiple network device
to form a group.
• Data, File or any media can be send by 1 party
to be received by multiple recipient.
MulticastSocket
Multicast Socket
• MulticastSocket class is a subclass from
DatagramSocket
– public class MulticastSocket extends DatagramSocket
• Calling class without parameter
– public MulticastSocket() throws SocketException
• Calling class with parameter port
– public MulticastSocket(int port) throws SocketException
• Calling class with parameter SocketAddress
– public MulticastSocket(SocketAddress bindAddress) throws
IOException
Multicast Socket
• Uses existing DatagramPacket object to form
the data need to be transmit
• MulticastSocket object is created on the
server or receiver side
– Example
• Later the object is bind to the server IP as
central grouping point
– Example

More Related Content

What's hot

Lecture 19 22. transport protocol for ad-hoc
Lecture 19 22. transport protocol for ad-hoc Lecture 19 22. transport protocol for ad-hoc
Lecture 19 22. transport protocol for ad-hoc
Chandra Meena
 

What's hot (20)

Network layer tanenbaum
Network layer tanenbaumNetwork layer tanenbaum
Network layer tanenbaum
 
Distance vector routing
Distance vector routingDistance vector routing
Distance vector routing
 
Congestion control in TCP
Congestion control in TCPCongestion control in TCP
Congestion control in TCP
 
IEEE Standards
IEEE StandardsIEEE Standards
IEEE Standards
 
Link state routing protocol
Link state routing protocolLink state routing protocol
Link state routing protocol
 
Mobile Network Layer
Mobile Network LayerMobile Network Layer
Mobile Network Layer
 
Address resolution protocol (ARP)
Address resolution protocol (ARP)Address resolution protocol (ARP)
Address resolution protocol (ARP)
 
Tcp Udp Icmp And The Transport Layer
Tcp Udp Icmp And The Transport LayerTcp Udp Icmp And The Transport Layer
Tcp Udp Icmp And The Transport Layer
 
Destination Sequenced Distance Vector Routing (DSDV)
Destination Sequenced Distance Vector Routing (DSDV)Destination Sequenced Distance Vector Routing (DSDV)
Destination Sequenced Distance Vector Routing (DSDV)
 
Application layer protocols
Application layer protocolsApplication layer protocols
Application layer protocols
 
Lecture 19 22. transport protocol for ad-hoc
Lecture 19 22. transport protocol for ad-hoc Lecture 19 22. transport protocol for ad-hoc
Lecture 19 22. transport protocol for ad-hoc
 
Datalinklayer tanenbaum
Datalinklayer tanenbaumDatalinklayer tanenbaum
Datalinklayer tanenbaum
 
Cs8591 u4
Cs8591 u4Cs8591 u4
Cs8591 u4
 
Framing in data link layer
Framing in data link layerFraming in data link layer
Framing in data link layer
 
TCP and UDP
TCP and UDP TCP and UDP
TCP and UDP
 
File Transfer Protocol
File Transfer ProtocolFile Transfer Protocol
File Transfer Protocol
 
Stop-and-Wait ARQ Protocol
Stop-and-Wait ARQ ProtocolStop-and-Wait ARQ Protocol
Stop-and-Wait ARQ Protocol
 
ICMP
ICMPICMP
ICMP
 
Ipv4 and Ipv6
Ipv4 and Ipv6Ipv4 and Ipv6
Ipv4 and Ipv6
 
data-link layer protocols
data-link layer protocols  data-link layer protocols
data-link layer protocols
 

Viewers also liked

User datagram protocol
User datagram protocolUser datagram protocol
User datagram protocol
Mohd Arif
 
Introduction of tcp, ip & udp
Introduction of tcp, ip & udpIntroduction of tcp, ip & udp
Introduction of tcp, ip & udp
rahul kundu
 
User Datagram protocol For Msc CS
User Datagram protocol For Msc CSUser Datagram protocol For Msc CS
User Datagram protocol For Msc CS
Thanveen
 
Unit III IPV6 UDP
Unit III IPV6 UDPUnit III IPV6 UDP
Unit III IPV6 UDP
sangusajjan
 
Presentation on telnet
Presentation on telnetPresentation on telnet
Presentation on telnet
Amandeep Kaur
 
TCP/IP Model
TCP/IP ModelTCP/IP Model
TCP/IP Model
farhan516
 
TCP/IP Network ppt
TCP/IP Network pptTCP/IP Network ppt
TCP/IP Network ppt
extraganesh
 

Viewers also liked (20)

User datagram protocol (udp)
User datagram protocol (udp)User datagram protocol (udp)
User datagram protocol (udp)
 
User datagram protocol
User datagram protocolUser datagram protocol
User datagram protocol
 
TCP & UDP protocols
TCP & UDP protocols TCP & UDP protocols
TCP & UDP protocols
 
Tcp and udp
Tcp and udpTcp and udp
Tcp and udp
 
TCP Vs UDP
TCP Vs UDP TCP Vs UDP
TCP Vs UDP
 
User datagram protocol
User datagram protocolUser datagram protocol
User datagram protocol
 
TCP- Transmission Control Protocol
TCP-  Transmission Control Protocol TCP-  Transmission Control Protocol
TCP- Transmission Control Protocol
 
Tcp
TcpTcp
Tcp
 
TCP Model
TCP ModelTCP Model
TCP Model
 
Introduction of tcp, ip & udp
Introduction of tcp, ip & udpIntroduction of tcp, ip & udp
Introduction of tcp, ip & udp
 
TCP - Transmission Control Protocol
TCP - Transmission Control ProtocolTCP - Transmission Control Protocol
TCP - Transmission Control Protocol
 
User Datagram protocol For Msc CS
User Datagram protocol For Msc CSUser Datagram protocol For Msc CS
User Datagram protocol For Msc CS
 
Unit III IPV6 UDP
Unit III IPV6 UDPUnit III IPV6 UDP
Unit III IPV6 UDP
 
Socket programming
Socket programmingSocket programming
Socket programming
 
Presentation on telnet
Presentation on telnetPresentation on telnet
Presentation on telnet
 
TCP/IP Model
TCP/IP ModelTCP/IP Model
TCP/IP Model
 
TCP/IP – Transmission Control Protocol/ Internet Protocol
TCP/IP – Transmission Control Protocol/ Internet ProtocolTCP/IP – Transmission Control Protocol/ Internet Protocol
TCP/IP – Transmission Control Protocol/ Internet Protocol
 
Internet protocol (ip) ppt
Internet protocol (ip) pptInternet protocol (ip) ppt
Internet protocol (ip) ppt
 
TCP/IP Network ppt
TCP/IP Network pptTCP/IP Network ppt
TCP/IP Network ppt
 
Socket programming
Socket programming Socket programming
Socket programming
 

Similar to Chapter 3 : User Datagram Protocol (UDP)

Udp Programming
Udp ProgrammingUdp Programming
Udp Programming
phanleson
 
Java- Datagram Socket class & Datagram Packet class
Java- Datagram Socket class  & Datagram Packet classJava- Datagram Socket class  & Datagram Packet class
Java- Datagram Socket class & Datagram Packet class
Ruchi Maurya
 

Similar to Chapter 3 : User Datagram Protocol (UDP) (20)

Easy Steps to implement UDP Server and Client Sockets
Easy Steps to implement UDP Server and Client SocketsEasy Steps to implement UDP Server and Client Sockets
Easy Steps to implement UDP Server and Client Sockets
 
Udp Programming
Udp ProgrammingUdp Programming
Udp Programming
 
Udp Programming
Udp ProgrammingUdp Programming
Udp Programming
 
Java socket presentation
Java socket presentation Java socket presentation
Java socket presentation
 
28 networking
28  networking28  networking
28 networking
 
Networking in Java
Networking in JavaNetworking in Java
Networking in Java
 
Advance Java-Network Programming
Advance Java-Network ProgrammingAdvance Java-Network Programming
Advance Java-Network Programming
 
Java- Datagram Socket class & Datagram Packet class
Java- Datagram Socket class  & Datagram Packet classJava- Datagram Socket class  & Datagram Packet class
Java- Datagram Socket class & Datagram Packet class
 
#2 (UDP)
#2 (UDP)#2 (UDP)
#2 (UDP)
 
Datagrams
DatagramsDatagrams
Datagrams
 
Ipc
IpcIpc
Ipc
 
Lecture6
Lecture6Lecture6
Lecture6
 
Network programming in Java
Network programming in JavaNetwork programming in Java
Network programming in Java
 
Networking.ppt(client/server, socket) uses in program
Networking.ppt(client/server, socket) uses in programNetworking.ppt(client/server, socket) uses in program
Networking.ppt(client/server, socket) uses in program
 
5_6278455688045789623.pptx
5_6278455688045789623.pptx5_6278455688045789623.pptx
5_6278455688045789623.pptx
 
Client server chat application
Client server chat applicationClient server chat application
Client server chat application
 
Developing Realtime Data Pipelines With Apache Kafka
Developing Realtime Data Pipelines With Apache KafkaDeveloping Realtime Data Pipelines With Apache Kafka
Developing Realtime Data Pipelines With Apache Kafka
 
Socket.io v.0.8.3
Socket.io v.0.8.3Socket.io v.0.8.3
Socket.io v.0.8.3
 
Socket.io v.0.8.3
Socket.io v.0.8.3Socket.io v.0.8.3
Socket.io v.0.8.3
 
Spark Summit EU talk by Sol Ackerman and Franklyn D'souza
Spark Summit EU talk by Sol Ackerman and Franklyn D'souzaSpark Summit EU talk by Sol Ackerman and Franklyn D'souza
Spark Summit EU talk by Sol Ackerman and Franklyn D'souza
 

Recently uploaded

Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Krashi Coaching
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
PECB
 

Recently uploaded (20)

Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 

Chapter 3 : User Datagram Protocol (UDP)

  • 1. CHAPTER 3 : User Datagram Protocol (UDP) By : Mr. Asyran Zarizi Bin Abdullah
  • 2. User Datagram Protocol • It’s a connection-less oriented protocol • Simpler and less overhead compared to TCP • Two important classes provided by Java API under java.net – DatagramSocket • Class that support data transmission between sender and receiver – DatagramPacket • Class that support data packet formation
  • 4. Java.net API • Socket in JAVA will divide by 3 type : – Socket client for TCP (stream) • Java.net.Socket – Socket server for TCP (stream) • Java.net.ServerSocket – Socket server for UDP • Java.net.DatagramSocket
  • 5. java.net.DatagramSocket class • Class that use to send and receive DatagramPacket from or to network • Datagram is an information but no guarantee of its content, arrival queue and arrival time. Constructor 1) DatagramSocket (int port) 2) DatagramSocket(int port, InetAddress inet) 3) DatagramSocket() Sample Syntax
  • 6. java.net.DatagramPacket class • Class use to represent a packet information (array byte) • Message that can be sent or received and can arrived in any order. Constructor 1) DatagramPacket(byte[], buf, int length) 2) DatagramPacket(byte[] buf, int length, InetAddress address, int port) Sample Syntax
  • 7. Methods • getData() : use to take an data information • getLenght() : use to take datagram length • getAddress() : use to take ip address information • getPort() : use to take port address information • Send(DatagramPacket data) : to send DatagramPacket to host and port destination • Receive(DatagramPacket data) : to block execution until receive 1 complete packet
  • 8. UDP Socket Structure Did you remember About previous lab (MySend) And (MyReceiver)?
  • 10. UDP vs TCP User Datagram Protocol (UDP) Transmission Control Protocol (TCP) Connectionless Oriented Connection-Oriented Provide datagram services Provide stream services No flow control, sequencing, and error recovery. Handles flow control, sequencing, and error recovery. Handles designation among processes in the same host by means of service port numbers. Handles designation among processes in the same host by means of service port numbers. There is a comparison between UDP and TCP
  • 11. Datagram Socket SERVER 1. Create a DatagramSocket object – DatagramSocket dgramSocket = new DatagramSocket(1234); 2. Create a buffer for incoming datagrams – byte[] buffer = new byte[256]; 3. Create a DatagramPacket object for the incoming datagram – DatagramPacket inPacket = new DatagramPacket(buffer,buffer.length); 4. Accept an incoming datagram – dgramSocket.receive(inPacket)
  • 12. Datagram Socket SERVER 5. Accept the sender’s address and port from the packet – InetAddress clientAddress = inPacket.getAddress(); – int clientPort = inPacket.getPort(); 6. Retrieve the data from the buffer – string message = new String(inPacket.getData(), 0, inPacket.getLength()); 7. Create the response datagram – DatagramPacket outPacket = new DatagramPacket(response.getBytes() , response.length(), clientAddress, clientPort); 8. Send the response datagram – dgramSocket.send(outPacket) 9. Close the DatagramSocket: dgram.close();
  • 13. Datagram Packet CLIENT 1. Create a DatagramSocket object – DatagramSocket dgramSocket = new DatagramSocket; 2. Create the outgoing datagram – DatagramPacket outPacket = new DatagramPacket(message.getBytes(), message.length(),host, port); 3. Send the datagram message – dgramSocket.send(outPacket) 4. Create a buffer for incoming datagrams – byte[] buffer = new byte[256];
  • 14. Datagram Packet CLIENT 5. Create a DatagramPacket object for the incoming datagram – DatagramPacket inPacket = new DatagramPacket(buffer, buffer.length); 6. Accept an incoming datagram – dgramSocket.receive(inPacket) 7. Retrieve the data from the buffer – string response = new String(inPacket.getData(), 0, inPacket.getLength()); 8. Close the DatagramSocket: – dgram.close();
  • 15. MulticastSocket • A class that use connection-less oriented protocol to connect multiple network device to form a group. • Data, File or any media can be send by 1 party to be received by multiple recipient.
  • 17. Multicast Socket • MulticastSocket class is a subclass from DatagramSocket – public class MulticastSocket extends DatagramSocket • Calling class without parameter – public MulticastSocket() throws SocketException • Calling class with parameter port – public MulticastSocket(int port) throws SocketException • Calling class with parameter SocketAddress – public MulticastSocket(SocketAddress bindAddress) throws IOException
  • 18. Multicast Socket • Uses existing DatagramPacket object to form the data need to be transmit • MulticastSocket object is created on the server or receiver side – Example • Later the object is bind to the server IP as central grouping point – Example