SlideShare a Scribd company logo
1 of 11
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

CS8662 Mobile Application Development Lab Manual
CS8662 Mobile Application Development Lab ManualCS8662 Mobile Application Development Lab Manual
CS8662 Mobile Application Development Lab Manualpkaviya
 
Software Engineering Fundamentals
Software Engineering FundamentalsSoftware Engineering Fundamentals
Software Engineering FundamentalsRahul Sudame
 
Database , 15 Object DBMS
Database , 15 Object DBMSDatabase , 15 Object DBMS
Database , 15 Object DBMSAli Usman
 
Object oriented testing
Object oriented testingObject oriented testing
Object oriented testingHaris Jamil
 
Deadlock Prevention
Deadlock PreventionDeadlock Prevention
Deadlock Preventionprachi mewara
 
Chapter 3 servlet & jsp
Chapter 3 servlet & jspChapter 3 servlet & jsp
Chapter 3 servlet & jspJafar Nesargi
 
Distributed computing
Distributed computingDistributed computing
Distributed computingshivli0769
 
Transaction management DBMS
Transaction  management DBMSTransaction  management DBMS
Transaction management DBMSMegha Patel
 
Distributed design alternatives
Distributed design alternativesDistributed design alternatives
Distributed design alternativesPooja Dixit
 
CLIENT SERVER IN OS.ppt
CLIENT SERVER IN OS.pptCLIENT SERVER IN OS.ppt
CLIENT SERVER IN OS.pptsuman yadav
 
Introduction to Design Pattern
Introduction to Design  PatternIntroduction to Design  Pattern
Introduction to Design PatternSanae BEKKAR
 
Java Networking
Java NetworkingJava Networking
Java NetworkingSunil OS
 
Software Engineering by Pankaj Jalote
Software Engineering by Pankaj JaloteSoftware Engineering by Pankaj Jalote
Software Engineering by Pankaj JaloteGolda Margret Sheeba J
 
Handheld operting system
Handheld operting systemHandheld operting system
Handheld operting systemAj Maurya
 
CS9222 ADVANCED OPERATING SYSTEMS
CS9222 ADVANCED OPERATING SYSTEMSCS9222 ADVANCED OPERATING SYSTEMS
CS9222 ADVANCED OPERATING SYSTEMSKathirvel Ayyaswamy
 
Object model
Object modelObject model
Object modelJames Wong
 
Complete dbms notes
Complete dbms notesComplete dbms notes
Complete dbms notesTanya Makkar
 

What's hot (20)

CS8662 Mobile Application Development Lab Manual
CS8662 Mobile Application Development Lab ManualCS8662 Mobile Application Development Lab Manual
CS8662 Mobile Application Development Lab Manual
 
Software Engineering Fundamentals
Software Engineering FundamentalsSoftware Engineering Fundamentals
Software Engineering Fundamentals
 
Database , 15 Object DBMS
Database , 15 Object DBMSDatabase , 15 Object DBMS
Database , 15 Object DBMS
 
Object oriented testing
Object oriented testingObject oriented testing
Object oriented testing
 
Deadlock Prevention
Deadlock PreventionDeadlock Prevention
Deadlock Prevention
 
Chapter 3 servlet & jsp
Chapter 3 servlet & jspChapter 3 servlet & jsp
Chapter 3 servlet & jsp
 
Distributed computing
Distributed computingDistributed computing
Distributed computing
 
Object Oriented Design
Object Oriented DesignObject Oriented Design
Object Oriented Design
 
Transaction management DBMS
Transaction  management DBMSTransaction  management DBMS
Transaction management DBMS
 
Distributed design alternatives
Distributed design alternativesDistributed design alternatives
Distributed design alternatives
 
CLIENT SERVER IN OS.ppt
CLIENT SERVER IN OS.pptCLIENT SERVER IN OS.ppt
CLIENT SERVER IN OS.ppt
 
Introduction to Design Pattern
Introduction to Design  PatternIntroduction to Design  Pattern
Introduction to Design Pattern
 
Java Networking
Java NetworkingJava Networking
Java Networking
 
operating system lecture notes
operating system lecture notesoperating system lecture notes
operating system lecture notes
 
Software Engineering by Pankaj Jalote
Software Engineering by Pankaj JaloteSoftware Engineering by Pankaj Jalote
Software Engineering by Pankaj Jalote
 
Handheld operting system
Handheld operting systemHandheld operting system
Handheld operting system
 
CS9222 ADVANCED OPERATING SYSTEMS
CS9222 ADVANCED OPERATING SYSTEMSCS9222 ADVANCED OPERATING SYSTEMS
CS9222 ADVANCED OPERATING SYSTEMS
 
Object model
Object modelObject model
Object model
 
Complete dbms notes
Complete dbms notesComplete dbms notes
Complete dbms notes
 
Java socket programming
Java socket programmingJava socket programming
Java socket programming
 

Viewers also liked

Socket Programming Tutorial
Socket Programming TutorialSocket Programming Tutorial
Socket Programming TutorialJignesh Patel
 
Socket programming
Socket programmingSocket programming
Socket programmingharsh_bca06
 
Network programming in java - PPT
Network programming in java - PPTNetwork programming in java - PPT
Network programming in java - PPTkamal 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 JavaTushar B Kute
 
Network Sockets
Network SocketsNetwork Sockets
Network SocketsPeter R. Egli
 
UDP - User Datagram Protocol
UDP - User Datagram ProtocolUDP - User Datagram Protocol
UDP - User Datagram ProtocolPeter R. Egli
 
Socket Programming - nitish nagar
Socket Programming - nitish nagarSocket Programming - nitish nagar
Socket Programming - nitish nagarNitish Nagar
 
Network Socket Programming with JAVA
Network Socket Programming with JAVANetwork Socket Programming with JAVA
Network Socket Programming with JAVADudy Ali
 
Sockets
SocketsSockets
Socketssivindia
 
Socket programming using java
Socket programming using javaSocket programming using java
Socket programming using javaUC San Diego
 
Jnp
JnpJnp
Jnphj43us
 
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
 

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
 
UDP - User Datagram Protocol
UDP - User Datagram ProtocolUDP - User Datagram Protocol
UDP - User Datagram Protocol
 
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
 

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
 
Advance Java-Network Programming
Advance Java-Network ProgrammingAdvance Java-Network Programming
Advance Java-Network Programmingashok 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 programgovindjha339843
 
Udp Programming
Udp ProgrammingUdp Programming
Udp Programmingleminhvuong
 
Udp Programming
Udp ProgrammingUdp Programming
Udp Programmingphanleson
 
Networks lab
Networks labNetworks lab
Networks labsvijiiii
 
Networks lab
Networks labNetworks lab
Networks labsvijiiii
 
Pemrograman Jaringan
Pemrograman JaringanPemrograman Jaringan
Pemrograman Jaringanbelajarkomputer
 
5_6278455688045789623.pptx
5_6278455688045789623.pptx5_6278455688045789623.pptx
5_6278455688045789623.pptxEliasPetros
 
Networking in Java
Networking in JavaNetworking in Java
Networking in JavaTushar B Kute
 
Chapter 4--converted.pptx
Chapter 4--converted.pptxChapter 4--converted.pptx
Chapter 4--converted.pptxWijdenBenothmen1
 
nw-lab_dns-server.pdf
nw-lab_dns-server.pdfnw-lab_dns-server.pdf
nw-lab_dns-server.pdfJayaprasanna4
 
Csphtp1 22
Csphtp1 22Csphtp1 22
Csphtp1 22HUST
 
Network programming in Java
Network programming in JavaNetwork programming in Java
Network programming in JavaTushar B Kute
 

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
 
Networking in Java
Networking in JavaNetworking in Java
Networking in Java
 
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
 

More from babak danyal

Java IO Package and Streams
Java IO Package and StreamsJava IO Package and Streams
Java IO Package and Streamsbabak 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 Javababak danyal
 
block ciphers and the des
block ciphers and the desblock ciphers and the des
block ciphers and the desbabak danyal
 
key distribution in network security
key distribution in network securitykey distribution in network security
key distribution in network securitybabak danyal
 
Lecture10 Signal and Systems
Lecture10 Signal and SystemsLecture10 Signal and Systems
Lecture10 Signal and Systemsbabak danyal
 
Lecture8 Signal and Systems
Lecture8 Signal and SystemsLecture8 Signal and Systems
Lecture8 Signal and Systemsbabak danyal
 
Lecture7 Signal and Systems
Lecture7 Signal and SystemsLecture7 Signal and Systems
Lecture7 Signal and Systemsbabak danyal
 
Lecture6 Signal and Systems
Lecture6 Signal and SystemsLecture6 Signal and Systems
Lecture6 Signal and Systemsbabak danyal
 
Lecture5 Signal and Systems
Lecture5 Signal and SystemsLecture5 Signal and Systems
Lecture5 Signal and Systemsbabak danyal
 
Lecture4 Signal and Systems
Lecture4  Signal and SystemsLecture4  Signal and Systems
Lecture4 Signal and Systemsbabak danyal
 
Lecture3 Signal and Systems
Lecture3 Signal and SystemsLecture3 Signal and Systems
Lecture3 Signal and Systemsbabak danyal
 
Lecture2 Signal and Systems
Lecture2 Signal and SystemsLecture2 Signal and Systems
Lecture2 Signal and Systemsbabak 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 Systemsbabak danyal
 
Cns 13f-lec03- Classical Encryption Techniques
Cns 13f-lec03- Classical Encryption TechniquesCns 13f-lec03- Classical Encryption Techniques
Cns 13f-lec03- Classical Encryption Techniquesbabak danyal
 
Classical Encryption Techniques in Network Security
Classical Encryption Techniques in Network SecurityClassical Encryption Techniques in Network Security
Classical Encryption Techniques in Network Securitybabak 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 Pakistanbabak 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

Romantic Opera MUSIC FOR GRADE NINE pptx
Romantic Opera MUSIC FOR GRADE NINE pptxRomantic Opera MUSIC FOR GRADE NINE pptx
Romantic Opera MUSIC FOR GRADE NINE pptxsqpmdrvczh
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfMr Bounab Samir
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxDr.Ibrahim Hassaan
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Planning a health career 4th Quarter.pptx
Planning a health career 4th Quarter.pptxPlanning a health career 4th Quarter.pptx
Planning a health career 4th Quarter.pptxLigayaBacuel1
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfphamnguyenenglishnb
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Jisc
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfSpandanaRallapalli
 

Recently uploaded (20)

Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Romantic Opera MUSIC FOR GRADE NINE pptx
Romantic Opera MUSIC FOR GRADE NINE pptxRomantic Opera MUSIC FOR GRADE NINE pptx
Romantic Opera MUSIC FOR GRADE NINE pptx
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptx
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Planning a health career 4th Quarter.pptx
Planning a health career 4th Quarter.pptxPlanning a health career 4th Quarter.pptx
Planning a health career 4th Quarter.pptx
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdf
 
Rapple "Scholarly Communications and the Sustainable Development Goals"
Rapple "Scholarly Communications and the Sustainable Development Goals"Rapple "Scholarly Communications and the Sustainable Development Goals"
Rapple "Scholarly Communications and the Sustainable Development Goals"
 

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();