SlideShare ist ein Scribd-Unternehmen logo
1 von 18
Downloaden Sie, um offline zu lesen
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

Weitere ähnliche Inhalte

Was ist angesagt?

Introduction of tcp, ip & udp
Introduction of tcp, ip & udpIntroduction of tcp, ip & udp
Introduction of tcp, ip & udp
rahul kundu
 

Was ist angesagt? (20)

TCP protocol flow control
TCP protocol flow control TCP protocol flow control
TCP protocol flow control
 
Trace route
Trace routeTrace route
Trace route
 
Network Layer,Computer Networks
Network Layer,Computer NetworksNetwork Layer,Computer Networks
Network Layer,Computer Networks
 
Transport layer protocol
Transport layer protocolTransport layer protocol
Transport layer protocol
 
Computer Networks Unit 2 UNIT II DATA-LINK LAYER & MEDIA ACCESS
Computer Networks Unit 2 UNIT II DATA-LINK LAYER & MEDIA ACCESSComputer Networks Unit 2 UNIT II DATA-LINK LAYER & MEDIA ACCESS
Computer Networks Unit 2 UNIT II DATA-LINK LAYER & MEDIA ACCESS
 
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
 
transport layer
transport layertransport layer
transport layer
 
Transport layer protocols : TCP and UDP
Transport layer protocols  : TCP and UDPTransport layer protocols  : TCP and UDP
Transport layer protocols : TCP and UDP
 
TCP & UDP ( Transmission Control Protocol and User Datagram Protocol)
TCP & UDP ( Transmission Control Protocol and User Datagram Protocol)TCP & UDP ( Transmission Control Protocol and User Datagram Protocol)
TCP & UDP ( Transmission Control Protocol and User Datagram Protocol)
 
Unit 3 Network Layer PPT
Unit 3 Network Layer PPTUnit 3 Network Layer PPT
Unit 3 Network Layer PPT
 
The medium access sublayer
 The medium  access sublayer The medium  access sublayer
The medium access sublayer
 
Transport layer
Transport layer Transport layer
Transport layer
 
TCP Vs UDP
TCP Vs UDP TCP Vs UDP
TCP Vs UDP
 
Point to-point protocol (ppp)
Point to-point protocol (ppp)Point to-point protocol (ppp)
Point to-point protocol (ppp)
 
TCP/IP and UDP protocols
TCP/IP and UDP protocolsTCP/IP and UDP protocols
TCP/IP and UDP protocols
 
Tcp header/IP Header/Authentication header
Tcp header/IP Header/Authentication headerTcp header/IP Header/Authentication header
Tcp header/IP Header/Authentication header
 
TOKEN BUS & TOKEN RING.ppt
TOKEN BUS & TOKEN RING.pptTOKEN BUS & TOKEN RING.ppt
TOKEN BUS & TOKEN RING.ppt
 
Protocols and the TCP/IP Protocol Suite
Protocols and the TCP/IP Protocol SuiteProtocols and the TCP/IP Protocol Suite
Protocols and the TCP/IP Protocol Suite
 
Distance Vector Routing Protocols
Distance Vector Routing ProtocolsDistance Vector Routing Protocols
Distance Vector Routing Protocols
 
Introduction of tcp, ip & udp
Introduction of tcp, ip & udpIntroduction of tcp, ip & udp
Introduction of tcp, ip & udp
 

Andere mochten auch

User datagram protocol
User datagram protocolUser datagram protocol
User datagram protocol
Mohd Arif
 
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
 
Tcp Udp
Tcp UdpTcp Udp
Tcp Udp
yanhul
 

Andere mochten auch (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
 
User datagram protocol
User datagram protocolUser datagram protocol
User datagram protocol
 
Transmission Control Protocol (TCP)
Transmission Control Protocol (TCP)Transmission Control Protocol (TCP)
Transmission Control Protocol (TCP)
 
TCP- Transmission Control Protocol
TCP-  Transmission Control Protocol TCP-  Transmission Control Protocol
TCP- Transmission Control Protocol
 
TCP Model
TCP ModelTCP Model
TCP Model
 
TCP - Transmission Control Protocol
TCP - Transmission Control ProtocolTCP - Transmission Control Protocol
TCP - Transmission Control Protocol
 
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
 
Tcp Udp
Tcp UdpTcp Udp
Tcp Udp
 
Unity Photon server 基礎設施
Unity Photon server 基礎設施Unity Photon server 基礎設施
Unity Photon server 基礎設施
 
An overview of TCP (Transmission Control Protocol)
An overview of TCP (Transmission Control Protocol)An overview of TCP (Transmission Control Protocol)
An overview of TCP (Transmission Control Protocol)
 

Ähnlich wie 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
 

Ähnlich wie 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
 

Kürzlich hochgeladen

The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 
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
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
negromaestrong
 

Kürzlich hochgeladen (20)

Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
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
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Role Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptxRole Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptx
 
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
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-IIFood Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
 

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