SlideShare a Scribd company logo
Java Network Programming
Datagram (UDP) Sockets
• Unlike TCP/IP sockets, datagram sockets are
connectionless
• Connection between client and server is not
maintained throughout the duration of the
dialogue
• Each datagram packet is sent as an isolated
transmission
• Datagram (UDP) sockets provide a faster means
of transmitting data than TCP/IP sockets, but
they are unreliable.
Datagram (UDP) Sockets (contd)
• The server does not create an individual Socket
object for each client
• Instead of a ServerSocket object, the server creates a
DatagramSocket object
• As does each client when it wants to send
datagram(s) to the server
• DatagramPacket objects are created and sent at
both ends, rather than simple Strings.
UDP Server
• Process involves the following nine steps
1. Create a DatagramSocket object
DatagramSocket datagramSocket =
new DatagramSocket(1234);
2.Create a buffer for incoming datagrams
byte[] buffer = new byte[256];
UDP Server (Contd)
3. Create a DatagramPacket object for the
incoming datagram
• The constructor for this object requires two
arguments:
• the previously-created byte array
• the size of this array
DatagramPacket inPacket =
new DatagramPacket(buffer, buffer.length);
UDP Server (Contd)
4. Accept an incoming datagram
datagramSocket.receive(inPacket);
5. Retrieve the sender's address and port from the
packet
InetAddress clientAddress = inPacket.getAddress();
int clientPort = inPacket.getPort();
UDP Server (contd)
6. Retrieve the data from the buffer
String message = new String(inPacket.getData(),
0,inPacket.getLength());
7. Create the response datagram
– Create a DatagramPacket object, using an overloaded
form of the constructor thattakes four arguments:
• the byte array containing the response message;
• the size of the response;
• the client's address;
• the client's port number.
UDP Server (contd)
DatagramPacket outPacket =
new DatagramPacket(response.getBytes(),
response.length(),clientAddress, clientPort);
8.Send the response datagram
datagramSocket.send(outPacket);
9.Close the DatagramSocket
datagramSocket.close();
UDP Client
• Setting up the corresponding client requires the
eight steps listed below
1. Create a DatagramSocket object
DatagramSocket datagramSocket = new DatagramSocket();
2. Create the outgoing datagram
• This step is exactly as for step 7 of the server
program
DatagramPacket outPacket =
new DatagramPacket(message.getBytes(),
message.length(), host, PORT);
UDP Client (contd)
3. Send the datagram message
datagramSocket.send(outPacket);
4. Create a buffer for incoming datagrams
byte[] buffer = new byte[256];
5.Create a DatagramPacket object for the
incoming datagrams
DatagramPacket inPacket =
new DatagramPacket(buffer, buffer.length);
UDP Client (contd)
6. Accept an incoming datagram
datagramSocket.receive(inPacket);
6. Retrieve the data from the buffer
String message = new String(inPacket.getData(),
0,inPacket.getLength());
8. Close the DatagramSocket
datagramSocket.close();

More Related Content

What's hot

RPC: Remote procedure call
RPC: Remote procedure callRPC: Remote procedure call
RPC: Remote procedure call
Sunita Sahu
 
Cryptography and network security
Cryptography and network securityCryptography and network security
Cryptography and network securitypatisa
 
OSI Model
OSI ModelOSI Model
OSI Model
Rahul Bandhe
 
Transport layer protocol
Transport layer protocolTransport layer protocol
Transport layer protocol
N.Jagadish Kumar
 
Computer organisation -morris mano
Computer organisation  -morris manoComputer organisation  -morris mano
Computer organisation -morris mano
vishnu murthy
 
Network Layer design Issues.pptx
Network Layer design Issues.pptxNetwork Layer design Issues.pptx
Network Layer design Issues.pptx
Acad
 
M.A.C (Medium Access Control)
M.A.C (Medium Access Control)M.A.C (Medium Access Control)
M.A.C (Medium Access Control)
JaironLanda
 
Internetworking
InternetworkingInternetworking
InternetworkingRaghu nath
 
TCP and UDP
TCP and UDP TCP and UDP
TCP and UDP
Ramesh Giri
 
Framing in data link layer
Framing in data link layerFraming in data link layer
Framing in data link layer
Ahtesham Ullah khan
 
Simple Mail Transfer Protocol
Simple Mail Transfer ProtocolSimple Mail Transfer Protocol
Simple Mail Transfer Protocol
Ujjayanta Bhaumik
 
Sliding window protocol
Sliding window protocolSliding window protocol
Sliding window protocol
Shehara Abeythunga
 
Socket programming in Java (PPTX)
Socket programming in Java (PPTX)Socket programming in Java (PPTX)
Socket programming in Java (PPTX)UC San Diego
 
Inter Process Communication Presentation[1]
Inter Process Communication Presentation[1]Inter Process Communication Presentation[1]
Inter Process Communication Presentation[1]Ravindra Raju Kolahalam
 
Internet control message protocol
Internet control message protocolInternet control message protocol
Internet control message protocolasimnawaz54
 
Socket Programming
Socket ProgrammingSocket Programming
Socket Programming
CEC Landran
 
Message authentication
Message authenticationMessage authentication
Message authentication
CAS
 
Tcp/ip model and protocol
Tcp/ip model and protocolTcp/ip model and protocol
Tcp/ip model and protocol
Laxman Choudhary
 
Network layer tanenbaum
Network layer tanenbaumNetwork layer tanenbaum
Network layer tanenbaum
Mahesh Kumar Chelimilla
 

What's hot (20)

RPC: Remote procedure call
RPC: Remote procedure callRPC: Remote procedure call
RPC: Remote procedure call
 
Cryptography and network security
Cryptography and network securityCryptography and network security
Cryptography and network security
 
OSI Model
OSI ModelOSI Model
OSI Model
 
Transport layer protocol
Transport layer protocolTransport layer protocol
Transport layer protocol
 
Computer organisation -morris mano
Computer organisation  -morris manoComputer organisation  -morris mano
Computer organisation -morris mano
 
Network Layer design Issues.pptx
Network Layer design Issues.pptxNetwork Layer design Issues.pptx
Network Layer design Issues.pptx
 
M.A.C (Medium Access Control)
M.A.C (Medium Access Control)M.A.C (Medium Access Control)
M.A.C (Medium Access Control)
 
Internetworking
InternetworkingInternetworking
Internetworking
 
TCP and UDP
TCP and UDP TCP and UDP
TCP and UDP
 
Framing in data link layer
Framing in data link layerFraming in data link layer
Framing in data link layer
 
Simple Mail Transfer Protocol
Simple Mail Transfer ProtocolSimple Mail Transfer Protocol
Simple Mail Transfer Protocol
 
Sliding window protocol
Sliding window protocolSliding window protocol
Sliding window protocol
 
Socket programming in Java (PPTX)
Socket programming in Java (PPTX)Socket programming in Java (PPTX)
Socket programming in Java (PPTX)
 
Inter Process Communication Presentation[1]
Inter Process Communication Presentation[1]Inter Process Communication Presentation[1]
Inter Process Communication Presentation[1]
 
Internet control message protocol
Internet control message protocolInternet control message protocol
Internet control message protocol
 
Socket Programming
Socket ProgrammingSocket Programming
Socket Programming
 
Inter Process Communication
Inter Process CommunicationInter Process Communication
Inter Process Communication
 
Message authentication
Message authenticationMessage authentication
Message authentication
 
Tcp/ip model and protocol
Tcp/ip model and protocolTcp/ip model and protocol
Tcp/ip model and protocol
 
Network layer tanenbaum
Network layer tanenbaumNetwork layer tanenbaum
Network layer tanenbaum
 

Viewers also liked

Socket programming
Socket programmingSocket programming
Socket programming
chandramouligunnemeda
 
Socket Programming Tutorial
Socket Programming TutorialSocket Programming Tutorial
Socket Programming Tutorial
Jignesh Patel
 
Tcp sockets
Tcp socketsTcp sockets
Tcp sockets
babak danyal
 
Socket programming
Socket programmingSocket programming
Socket programming
harsh_bca06
 
Network programming in java - PPT
Network programming in java - PPTNetwork programming in java - PPT
Network programming in java - PPT
kamal kotecha
 
Networking Java Socket Programming
Networking Java Socket ProgrammingNetworking Java Socket Programming
Networking Java Socket ProgrammingMousmi Pawar
 
Ports & sockets
Ports  & sockets Ports  & sockets
Ports & sockets
myrajendra
 
Network programming in Java
Network programming in JavaNetwork programming in Java
Network programming in Java
Tushar B Kute
 
Network Sockets
Network SocketsNetwork Sockets
Network Sockets
Peter R. Egli
 
Socket Programming - nitish nagar
Socket Programming - nitish nagarSocket Programming - nitish nagar
Socket Programming - nitish nagar
Nitish Nagar
 
Network Socket Programming with JAVA
Network Socket Programming with JAVANetwork Socket Programming with JAVA
Network Socket Programming with JAVA
Dudy Ali
 
Basics of sockets
Basics of socketsBasics of sockets
Basics of sockets
AviNash ChaVhan
 
Socket programming using java
Socket programming using javaSocket programming using java
Socket programming using java
UC San Diego
 
Jnp
JnpJnp
Jnp
hj43us
 
Chat application in java using swing and socket programming.
Chat application in java using swing and socket programming.Chat application in java using swing and socket programming.
Chat application in java using swing and socket programming.
Kuldeep Jain
 
Rfc768
Rfc768Rfc768
Rfc768
Sriram Raj
 
Tcp udp
Tcp udpTcp udp
Tcp udp
Programmer
 
Networking in Java
Networking in JavaNetworking in Java
Networking in Java
Tushar B Kute
 

Viewers also liked (20)

Socket programming
Socket programmingSocket programming
Socket programming
 
Socket Programming Tutorial
Socket Programming TutorialSocket Programming Tutorial
Socket Programming Tutorial
 
Ppt of socket
Ppt of socketPpt of socket
Ppt of socket
 
Tcp sockets
Tcp socketsTcp sockets
Tcp sockets
 
Socket programming
Socket programmingSocket programming
Socket programming
 
Network programming in java - PPT
Network programming in java - PPTNetwork programming in java - PPT
Network programming in java - PPT
 
Networking Java Socket Programming
Networking Java Socket ProgrammingNetworking Java Socket Programming
Networking Java Socket Programming
 
Ports & sockets
Ports  & sockets Ports  & sockets
Ports & sockets
 
Network programming in Java
Network programming in JavaNetwork programming in Java
Network programming in Java
 
Network Sockets
Network SocketsNetwork Sockets
Network Sockets
 
Socket Programming - nitish nagar
Socket Programming - nitish nagarSocket Programming - nitish nagar
Socket Programming - nitish nagar
 
Network Socket Programming with JAVA
Network Socket Programming with JAVANetwork Socket Programming with JAVA
Network Socket Programming with JAVA
 
Sockets
SocketsSockets
Sockets
 
Basics of sockets
Basics of socketsBasics of sockets
Basics of sockets
 
Socket programming using java
Socket programming using javaSocket programming using java
Socket programming using java
 
Jnp
JnpJnp
Jnp
 
Chat application in java using swing and socket programming.
Chat application in java using swing and socket programming.Chat application in java using swing and socket programming.
Chat application in java using swing and socket programming.
 
Rfc768
Rfc768Rfc768
Rfc768
 
Tcp udp
Tcp udpTcp udp
Tcp udp
 
Networking in Java
Networking in JavaNetworking in Java
Networking in Java
 

Similar to Easy Steps to implement UDP Server and Client Sockets

Java socket presentation
Java socket presentation Java socket presentation
Java socket presentation
Zahidul Islam Razu
 
Chapter 3 : User Datagram Protocol (UDP)
Chapter 3 : User Datagram Protocol (UDP)Chapter 3 : User Datagram Protocol (UDP)
Chapter 3 : User Datagram Protocol (UDP)
Ministry of Higher Education
 
#2 (UDP)
#2 (UDP)#2 (UDP)
#2 (UDP)
Ghadeer AlHasan
 
Advance Java-Network Programming
Advance Java-Network ProgrammingAdvance Java-Network Programming
Advance Java-Network Programming
ashok hirpara
 
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
govindjha339843
 
Udp Programming
Udp ProgrammingUdp Programming
Udp Programmingphanleson
 
Networks lab
Networks labNetworks lab
Networks lab
svijiiii
 
Networks lab
Networks labNetworks lab
Networks labsvijiiii
 
Pemrograman Jaringan
Pemrograman JaringanPemrograman Jaringan
Pemrograman Jaringan
belajarkomputer
 
5_6278455688045789623.pptx
5_6278455688045789623.pptx5_6278455688045789623.pptx
5_6278455688045789623.pptx
EliasPetros
 
Chapter 4--converted.pptx
Chapter 4--converted.pptxChapter 4--converted.pptx
Chapter 4--converted.pptx
WijdenBenothmen1
 
nw-lab_dns-server.pdf
nw-lab_dns-server.pdfnw-lab_dns-server.pdf
nw-lab_dns-server.pdf
Jayaprasanna4
 
Java 1
Java 1Java 1
Csphtp1 22
Csphtp1 22Csphtp1 22
Csphtp1 22
HUST
 
Network programming in Java
Network programming in JavaNetwork programming in Java
Network programming in Java
Tushar B Kute
 
A.java
A.javaA.java

Similar to Easy Steps to implement UDP Server and Client Sockets (20)

Java socket presentation
Java socket presentation Java socket presentation
Java socket presentation
 
Chapter 3 : User Datagram Protocol (UDP)
Chapter 3 : User Datagram Protocol (UDP)Chapter 3 : User Datagram Protocol (UDP)
Chapter 3 : User Datagram Protocol (UDP)
 
#2 (UDP)
#2 (UDP)#2 (UDP)
#2 (UDP)
 
Advance Java-Network Programming
Advance Java-Network ProgrammingAdvance Java-Network Programming
Advance Java-Network Programming
 
Lecture6
Lecture6Lecture6
Lecture6
 
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
 
Udp Programming
Udp ProgrammingUdp Programming
Udp Programming
 
Udp Programming
Udp ProgrammingUdp Programming
Udp Programming
 
28 networking
28  networking28  networking
28 networking
 
Networks lab
Networks labNetworks lab
Networks lab
 
Networks lab
Networks labNetworks lab
Networks lab
 
Pemrograman Jaringan
Pemrograman JaringanPemrograman Jaringan
Pemrograman Jaringan
 
5_6278455688045789623.pptx
5_6278455688045789623.pptx5_6278455688045789623.pptx
5_6278455688045789623.pptx
 
Chapter 4--converted.pptx
Chapter 4--converted.pptxChapter 4--converted.pptx
Chapter 4--converted.pptx
 
nw-lab_dns-server.pdf
nw-lab_dns-server.pdfnw-lab_dns-server.pdf
nw-lab_dns-server.pdf
 
Md13 networking
Md13 networkingMd13 networking
Md13 networking
 
Java 1
Java 1Java 1
Java 1
 
Csphtp1 22
Csphtp1 22Csphtp1 22
Csphtp1 22
 
Network programming in Java
Network programming in JavaNetwork programming in Java
Network programming in Java
 
A.java
A.javaA.java
A.java
 

More from babak danyal

Java IO Package and Streams
Java IO Package and StreamsJava IO Package and Streams
Java IO Package and Streams
babak danyal
 
Swing and Graphical User Interface in Java
Swing and Graphical User Interface in JavaSwing and Graphical User Interface in Java
Swing and Graphical User Interface in Java
babak danyal
 
block ciphers and the des
block ciphers and the desblock ciphers and the des
block ciphers and the des
babak danyal
 
key distribution in network security
key distribution in network securitykey distribution in network security
key distribution in network security
babak danyal
 
Lecture10 Signal and Systems
Lecture10 Signal and SystemsLecture10 Signal and Systems
Lecture10 Signal and Systems
babak danyal
 
Lecture8 Signal and Systems
Lecture8 Signal and SystemsLecture8 Signal and Systems
Lecture8 Signal and Systems
babak danyal
 
Lecture7 Signal and Systems
Lecture7 Signal and SystemsLecture7 Signal and Systems
Lecture7 Signal and Systems
babak danyal
 
Lecture6 Signal and Systems
Lecture6 Signal and SystemsLecture6 Signal and Systems
Lecture6 Signal and Systems
babak danyal
 
Lecture5 Signal and Systems
Lecture5 Signal and SystemsLecture5 Signal and Systems
Lecture5 Signal and Systems
babak danyal
 
Lecture4 Signal and Systems
Lecture4  Signal and SystemsLecture4  Signal and Systems
Lecture4 Signal and Systems
babak danyal
 
Lecture3 Signal and Systems
Lecture3 Signal and SystemsLecture3 Signal and Systems
Lecture3 Signal and Systems
babak danyal
 
Lecture2 Signal and Systems
Lecture2 Signal and SystemsLecture2 Signal and Systems
Lecture2 Signal and Systems
babak danyal
 
Lecture1 Intro To Signa
Lecture1 Intro To SignaLecture1 Intro To Signa
Lecture1 Intro To Signababak danyal
 
Lecture9 Signal and Systems
Lecture9 Signal and SystemsLecture9 Signal and Systems
Lecture9 Signal and Systems
babak danyal
 
Cns 13f-lec03- Classical Encryption Techniques
Cns 13f-lec03- Classical Encryption TechniquesCns 13f-lec03- Classical Encryption Techniques
Cns 13f-lec03- Classical Encryption Techniques
babak danyal
 
Classical Encryption Techniques in Network Security
Classical Encryption Techniques in Network SecurityClassical Encryption Techniques in Network Security
Classical Encryption Techniques in Network Security
babak danyal
 
Problems at independence
Problems at independenceProblems at independence
Problems at independencebabak danyal
 
Quaid-e-Azam and Early Problems of Pakistan
Quaid-e-Azam and Early Problems of PakistanQuaid-e-Azam and Early Problems of Pakistan
Quaid-e-Azam and Early Problems of Pakistan
babak danyal
 

More from babak danyal (20)

applist
applistapplist
applist
 
Java IO Package and Streams
Java IO Package and StreamsJava IO Package and Streams
Java IO Package and Streams
 
Swing and Graphical User Interface in Java
Swing and Graphical User Interface in JavaSwing and Graphical User Interface in Java
Swing and Graphical User Interface in Java
 
block ciphers and the des
block ciphers and the desblock ciphers and the des
block ciphers and the des
 
key distribution in network security
key distribution in network securitykey distribution in network security
key distribution in network security
 
Lecture10 Signal and Systems
Lecture10 Signal and SystemsLecture10 Signal and Systems
Lecture10 Signal and Systems
 
Lecture8 Signal and Systems
Lecture8 Signal and SystemsLecture8 Signal and Systems
Lecture8 Signal and Systems
 
Lecture7 Signal and Systems
Lecture7 Signal and SystemsLecture7 Signal and Systems
Lecture7 Signal and Systems
 
Lecture6 Signal and Systems
Lecture6 Signal and SystemsLecture6 Signal and Systems
Lecture6 Signal and Systems
 
Lecture5 Signal and Systems
Lecture5 Signal and SystemsLecture5 Signal and Systems
Lecture5 Signal and Systems
 
Lecture4 Signal and Systems
Lecture4  Signal and SystemsLecture4  Signal and Systems
Lecture4 Signal and Systems
 
Lecture3 Signal and Systems
Lecture3 Signal and SystemsLecture3 Signal and Systems
Lecture3 Signal and Systems
 
Lecture2 Signal and Systems
Lecture2 Signal and SystemsLecture2 Signal and Systems
Lecture2 Signal and Systems
 
Lecture1 Intro To Signa
Lecture1 Intro To SignaLecture1 Intro To Signa
Lecture1 Intro To Signa
 
Lecture9 Signal and Systems
Lecture9 Signal and SystemsLecture9 Signal and Systems
Lecture9 Signal and Systems
 
Lecture9
Lecture9Lecture9
Lecture9
 
Cns 13f-lec03- Classical Encryption Techniques
Cns 13f-lec03- Classical Encryption TechniquesCns 13f-lec03- Classical Encryption Techniques
Cns 13f-lec03- Classical Encryption Techniques
 
Classical Encryption Techniques in Network Security
Classical Encryption Techniques in Network SecurityClassical Encryption Techniques in Network Security
Classical Encryption Techniques in Network Security
 
Problems at independence
Problems at independenceProblems at independence
Problems at independence
 
Quaid-e-Azam and Early Problems of Pakistan
Quaid-e-Azam and Early Problems of PakistanQuaid-e-Azam and Early Problems of Pakistan
Quaid-e-Azam and Early Problems of Pakistan
 

Recently uploaded

Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
chanes7
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
EduSkills OECD
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Dr. Vinod Kumar Kanvaria
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Akanksha trivedi rama nursing college kanpur.
 
The Diamond Necklace by Guy De Maupassant.pptx
The Diamond Necklace by Guy De Maupassant.pptxThe Diamond Necklace by Guy De Maupassant.pptx
The Diamond Necklace by Guy De Maupassant.pptx
DhatriParmar
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
TechSoup
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
Scholarhat
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
David Douglas School District
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
Multithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race conditionMultithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race condition
Mohammed Sikander
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
TechSoup
 

Recently uploaded (20)

Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
 
The Diamond Necklace by Guy De Maupassant.pptx
The Diamond Necklace by Guy De Maupassant.pptxThe Diamond Necklace by Guy De Maupassant.pptx
The Diamond Necklace by Guy De Maupassant.pptx
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
Multithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race conditionMultithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race condition
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
 

Easy Steps to implement UDP Server and Client Sockets

  • 2. Datagram (UDP) Sockets • Unlike TCP/IP sockets, datagram sockets are connectionless • Connection between client and server is not maintained throughout the duration of the dialogue • Each datagram packet is sent as an isolated transmission • Datagram (UDP) sockets provide a faster means of transmitting data than TCP/IP sockets, but they are unreliable.
  • 3. Datagram (UDP) Sockets (contd) • The server does not create an individual Socket object for each client • Instead of a ServerSocket object, the server creates a DatagramSocket object • As does each client when it wants to send datagram(s) to the server • DatagramPacket objects are created and sent at both ends, rather than simple Strings.
  • 4. UDP Server • Process involves the following nine steps 1. Create a DatagramSocket object DatagramSocket datagramSocket = new DatagramSocket(1234); 2.Create a buffer for incoming datagrams byte[] buffer = new byte[256];
  • 5. UDP Server (Contd) 3. Create a DatagramPacket object for the incoming datagram • The constructor for this object requires two arguments: • the previously-created byte array • the size of this array DatagramPacket inPacket = new DatagramPacket(buffer, buffer.length);
  • 6. UDP Server (Contd) 4. Accept an incoming datagram datagramSocket.receive(inPacket); 5. Retrieve the sender's address and port from the packet InetAddress clientAddress = inPacket.getAddress(); int clientPort = inPacket.getPort();
  • 7. UDP Server (contd) 6. Retrieve the data from the buffer String message = new String(inPacket.getData(), 0,inPacket.getLength()); 7. Create the response datagram – Create a DatagramPacket object, using an overloaded form of the constructor thattakes four arguments: • the byte array containing the response message; • the size of the response; • the client's address; • the client's port number.
  • 8. UDP Server (contd) DatagramPacket outPacket = new DatagramPacket(response.getBytes(), response.length(),clientAddress, clientPort); 8.Send the response datagram datagramSocket.send(outPacket); 9.Close the DatagramSocket datagramSocket.close();
  • 9. UDP Client • Setting up the corresponding client requires the eight steps listed below 1. Create a DatagramSocket object DatagramSocket datagramSocket = new DatagramSocket(); 2. Create the outgoing datagram • This step is exactly as for step 7 of the server program DatagramPacket outPacket = new DatagramPacket(message.getBytes(), message.length(), host, PORT);
  • 10. UDP Client (contd) 3. Send the datagram message datagramSocket.send(outPacket); 4. Create a buffer for incoming datagrams byte[] buffer = new byte[256]; 5.Create a DatagramPacket object for the incoming datagrams DatagramPacket inPacket = new DatagramPacket(buffer, buffer.length);
  • 11. UDP Client (contd) 6. Accept an incoming datagram datagramSocket.receive(inPacket); 6. Retrieve the data from the buffer String message = new String(inPacket.getData(), 0,inPacket.getLength()); 8. Close the DatagramSocket datagramSocket.close();