SlideShare ist ein Scribd-Unternehmen logo
1 von 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();

Weitere ähnliche Inhalte

Was ist angesagt?

Socket programming using C
Socket programming using CSocket programming using C
Socket programming using CAjit Nayak
 
Socket programming
Socket programmingSocket programming
Socket programmingAnurag Tomar
 
Ch 3 event driven programming
Ch 3 event driven programmingCh 3 event driven programming
Ch 3 event driven programmingChaffey College
 
Web essentials clients, servers and communication – the internet – basic inte...
Web essentials clients, servers and communication – the internet – basic inte...Web essentials clients, servers and communication – the internet – basic inte...
Web essentials clients, servers and communication – the internet – basic inte...smitha273566
 
Network programming in java - PPT
Network programming in java - PPTNetwork programming in java - PPT
Network programming in java - PPTkamal kotecha
 
INTERAKSI MANUSIA DAN KOMPUTER
INTERAKSI MANUSIA DAN KOMPUTERINTERAKSI MANUSIA DAN KOMPUTER
INTERAKSI MANUSIA DAN KOMPUTERAndhi Pratama
 
ALOHA Protocol (in detail)
ALOHA Protocol (in detail)ALOHA Protocol (in detail)
ALOHA Protocol (in detail)Hinal Lunagariya
 
TCP - IP Presentation
TCP - IP PresentationTCP - IP Presentation
TCP - IP PresentationHarish Chand
 
Transport Layer Services : Multiplexing And Demultiplexing
Transport Layer Services : Multiplexing And DemultiplexingTransport Layer Services : Multiplexing And Demultiplexing
Transport Layer Services : Multiplexing And DemultiplexingKeyur Vadodariya
 
User datagram protocol (udp)
User datagram protocol (udp)User datagram protocol (udp)
User datagram protocol (udp)Ramola Dhande
 
Servlet and servlet life cycle
Servlet and servlet life cycleServlet and servlet life cycle
Servlet and servlet life cycleDhruvin Nakrani
 

Was ist angesagt? (20)

Socket programming using C
Socket programming using CSocket programming using C
Socket programming using C
 
Socket programming
Socket programmingSocket programming
Socket programming
 
Ch 3 event driven programming
Ch 3 event driven programmingCh 3 event driven programming
Ch 3 event driven programming
 
Web essentials clients, servers and communication – the internet – basic inte...
Web essentials clients, servers and communication – the internet – basic inte...Web essentials clients, servers and communication – the internet – basic inte...
Web essentials clients, servers and communication – the internet – basic inte...
 
Ppt of socket
Ppt of socketPpt of socket
Ppt of socket
 
Simple object access protocol(soap )
Simple object access protocol(soap )Simple object access protocol(soap )
Simple object access protocol(soap )
 
Application Layer
Application LayerApplication Layer
Application Layer
 
Smtp, pop3, imapv 4
Smtp, pop3, imapv 4Smtp, pop3, imapv 4
Smtp, pop3, imapv 4
 
Webservices
WebservicesWebservices
Webservices
 
Network programming in java - PPT
Network programming in java - PPTNetwork programming in java - PPT
Network programming in java - PPT
 
INTERAKSI MANUSIA DAN KOMPUTER
INTERAKSI MANUSIA DAN KOMPUTERINTERAKSI MANUSIA DAN KOMPUTER
INTERAKSI MANUSIA DAN KOMPUTER
 
TCP and UDP
TCP and UDP TCP and UDP
TCP and UDP
 
ALOHA Protocol (in detail)
ALOHA Protocol (in detail)ALOHA Protocol (in detail)
ALOHA Protocol (in detail)
 
Android UI
Android UIAndroid UI
Android UI
 
TCP - IP Presentation
TCP - IP PresentationTCP - IP Presentation
TCP - IP Presentation
 
Transport Layer Services : Multiplexing And Demultiplexing
Transport Layer Services : Multiplexing And DemultiplexingTransport Layer Services : Multiplexing And Demultiplexing
Transport Layer Services : Multiplexing And Demultiplexing
 
User datagram protocol (udp)
User datagram protocol (udp)User datagram protocol (udp)
User datagram protocol (udp)
 
Servlet and servlet life cycle
Servlet and servlet life cycleServlet and servlet life cycle
Servlet and servlet life cycle
 
Network Layer by-adeel
Network Layer by-adeelNetwork Layer by-adeel
Network Layer by-adeel
 
WSDL
WSDLWSDL
WSDL
 

Andere mochten auch

Socket Programming Tutorial
Socket Programming TutorialSocket Programming Tutorial
Socket Programming TutorialJignesh Patel
 
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
 
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
 
Socket programming using java
Socket programming using javaSocket programming using java
Socket programming using javaUC San Diego
 
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
 
Fellow Developers, Let's Discover Your Superpower
Fellow Developers, Let's Discover Your SuperpowerFellow Developers, Let's Discover Your Superpower
Fellow Developers, Let's Discover Your SuperpowerRiza Fahmi
 
Mobile Programming - 3 UDP
Mobile Programming - 3 UDPMobile Programming - 3 UDP
Mobile Programming - 3 UDPRiza Fahmi
 

Andere mochten auch (20)

Socket programming
Socket programmingSocket programming
Socket programming
 
Socket Programming Tutorial
Socket Programming TutorialSocket Programming Tutorial
Socket Programming Tutorial
 
Tcp sockets
Tcp socketsTcp sockets
Tcp sockets
 
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
 
Networking in Java
Networking in JavaNetworking in Java
Networking in Java
 
Fellow Developers, Let's Discover Your Superpower
Fellow Developers, Let's Discover Your SuperpowerFellow Developers, Let's Discover Your Superpower
Fellow Developers, Let's Discover Your Superpower
 
Mobile Programming - 3 UDP
Mobile Programming - 3 UDPMobile Programming - 3 UDP
Mobile Programming - 3 UDP
 

Ähnlich wie Easy Steps to implement UDP Server and Client Sockets

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

Mehr von 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
 

Mehr von 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
 

Kürzlich hochgeladen

GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSJoshuaGantuangco2
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designMIPLM
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxHumphrey A Beña
 
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptx
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptxMusic 9 - 4th quarter - Vocal Music of the Romantic Period.pptx
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptxleah joy valeriano
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management SystemChristalin Nelson
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)lakshayb543
 
Active Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfActive Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfPatidar M
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...Nguyen Thanh Tu Collection
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
ROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxVanesaIglesias10
 
Integumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.pptIntegumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.pptshraddhaparab530
 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptxmary850239
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYKayeClaireEstoconing
 
Food processing presentation for bsc agriculture hons
Food processing presentation for bsc agriculture honsFood processing presentation for bsc agriculture hons
Food processing presentation for bsc agriculture honsManeerUddin
 

Kürzlich hochgeladen (20)

GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-design
 
Raw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptxRaw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptx
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
 
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptx
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptxMusic 9 - 4th quarter - Vocal Music of the Romantic Period.pptx
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptx
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management System
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
 
Active Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfActive Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdf
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
ROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptx
 
Integumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.pptIntegumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.ppt
 
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptxYOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx
 
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptxLEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
 
Food processing presentation for bsc agriculture hons
Food processing presentation for bsc agriculture honsFood processing presentation for bsc agriculture hons
Food processing presentation for bsc agriculture hons
 

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