SlideShare a Scribd company logo
Q7M1 – SC Dudy Fathan Ali S.Kom
Network Socket Programming
Q7M1
Dudy Fathan Ali, S.Kom (DFA)
2017
CEP - CCIT
Fakultas Teknik Universitas Indonesia
Consider this scenario..
Q7M1 – SC Dudy Fathan Ali S.Kom
Hello, I want a
pizza.
Guys, bob
wants a pizza!
Bob
Pizza Store
Consider this scenario..
Q7M1 – SC Dudy Fathan Ali S.Kom
Pizza Store
Standard Operational Procedure
Hmm..
Q7M1 – SC Dudy Fathan Ali S.Kom
Client/Server Architecture
Q7M1 – SC Dudy Fathan Ali S.Kom
Bob
[Client]
Pizza Store
[Server]
The client places a
request or order
to the server.
The server processes
the request of the
client
The communication
between the client
and the server is
usually through a
network.
The Client/Server model is an application development architecture designed to separate
the presentation of data from its internal processing and storage.
Client/Server Architecture
Q7M1 – SC Dudy Fathan Ali S.Kom
Pizza Store
The processing that is done by the server is hidden from the client.
Client/Server Architecture
Q7M1 – SC Dudy Fathan Ali S.Kom
Steve
Bob
John
One server can service multiple clients.
Client/Server Architecture
Q7M1 – SC Dudy Fathan Ali S.Kom
The server and the client are not necessarily hardware components.
They can be programs working on the same machine or on different
machines.
Internet Protocol
Q7M1 – SC Dudy Fathan Ali S.Kom
The Internet Protocol (IP) is the principal communications protocol in the
Internet protocol suite for relaying datagrams across network boundaries.
Its routing function enables internetworking, and essentially establishes
the Internet.
-- Source: wikipedia.org
-- Source: google.com
Internet Protocol
Q7M1 – SC Dudy Fathan Ali S.Kom
implicit rules in conversation?
Internet Protocol
Q7M1 – SC Dudy Fathan Ali S.Kom
o Data is sent from one machine to another in form of packets.
o Rules govern packaging of data into packets, speed of transmission, and
reassembling of data into its original form.
o These rules are called network protocols.
Communication rules between computers
IP Address & Port
Q7M1 – SC Dudy Fathan Ali S.Kom
IP Address & Port
Q7M1 – SC Dudy Fathan Ali S.Kom
The TCP protocol requires two data items: the IP address
and the port number.
172.17.8.192 : 80
IP Address Port
o Well-known ports
o Registered ports
o Dynamic/Private ports
IP Address & Port
Q7M1 – SC Dudy Fathan Ali S.Kom
IP Addresses of Popular Websites
Sockets
Q7M1 – SC Dudy Fathan Ali S.Kom
Sockets are used to handle the communication links between
applications over the network. Further communication between the
client and the server is through the socket.
-- Source: NIIT Courseware Q7M1
Java Classes for Network Programming
Q7M1 – SC Dudy Fathan Ali S.Kom
o The java.net package of the Java programming language contains
classes and interfaces that provide support for networking.
o Networking classes contain methods to perform tasks, such as
opening and closing a connection to remote machine, sending and
receiving data packets and accessing resources on the Web.
Java Classes for Network Programming
Q7M1 – SC Dudy Fathan Ali S.Kom
Classes of the java.net Package:
o DatagramPacket
o Represents a datagram packet.
o DatagramSocket
o Represents a datagram socket object that can send and receive datagram
packets.
o MulticastSocket
o Creates a multicast datagram socket object that is used to send and receive
datagram packets to groups.
o InetAddress
o Represents an IP address.
o ServerSocket
o Represents a TCP/IP server socket object that receives connection requests from
the clients.
Java Classes for Network Programming
Q7M1 – SC Dudy Fathan Ali S.Kom
The InetAddress Class:
o Represents an IP address.
o Contains the following static methods to initialize InetAddress
objects:
o public static InetAddress getLocalHost()
o public static InetAddress getByName(String host)
o public static InetAddress[] getAllByName(String host)
Java Classes for Network Programming
Q7M1 – SC Dudy Fathan Ali S.Kom
The non-static methods of the InetAddress class are:
o public boolean equals(Object obj)
o public byte[] getAddress()
o public String getHostAddress()
o public String toString()
Java Classes for Network Programming
Q7M1 – SC Dudy Fathan Ali S.Kom
Code Example:
Result:
Returns an
InetAddress object
that contains the IP
address of the local
computer.
Returns the IP address of
the InetAddress
object as a String.
TCP vs UDP
Q7M1 – SC Dudy Fathan Ali S.Kom
TCP vs UDP
Q7M1 – SC Dudy Fathan Ali S.Kom
Creating Application Using UDP
Q7M1 – SC Dudy Fathan Ali S.Kom
o UDP is a fast, connectionless, and unreliable protocol.
o UDP sockets use UDP protocol for communication over a network.
o The java.net package provides the following two classes that
enable you to implement UDP sockets in a Java application:
o DatagramPacket class
o DatagramSocket class
o The DatagramPacket object is a data container that consists of
datagram packets that are sent or received over the network.
o The constructor used to initialize DatagramPacket objects are:
o public DatagramPacket( byte[] buffer, int
buffer_length)
o public DatagramPacket( byte[] buffer, int
buffer_length, InetAddress address, int port)
Creating Application Using UDP
Q7M1 – SC Dudy Fathan Ali S.Kom
o DatagramSocket class encapsulates the functionality to handle
DatagramPacket objects.
o The constructors used to initialize DatagramSocket object are:
o public DatagramSocket()
o public DatagramSocket(int port)
o public DatagramSocket(int port, InetAddress
address)
Creating Application Using UDP
Q7M1 – SC Dudy Fathan Ali S.Kom
Code Example [DataSender]:
Creating Application Using UDP
Q7M1 – SC Dudy Fathan Ali S.Kom
Code Example [DataReceiver]:
Demonstration-Implementing UDP
Q7M1 – SC Dudy Fathan Ali S.Kom
Create a Client/Server
application where the server
can broadcast messages to all
the clients of 233.0.0.1 group.
Q7M1 – SC Dudy Fathan Ali S.Kom
Thank You!
Dudy Fathan Ali, S.Kom
dudy.fathan@eng.ui.ac.id

More Related Content

PDF
Socket Programming using Java
Rahul Hada
Ā 
PPT
Socket Programming
CEC Landran
Ā 
PDF
Socket programming
NemiRathore
Ā 
PPT
Np unit2
vamsitricks
Ā 
PPTX
IPC SOCKET
Sanoj Kumar
Ā 
PPT
Unit III IPV6 UDP
sangusajjan
Ā 
PDF
Networking lab
Ragu Ram
Ā 
PDF
The Considerations for Internet of Things @ 2017
Jian-Hong Pan
Ā 
Socket Programming using Java
Rahul Hada
Ā 
Socket Programming
CEC Landran
Ā 
Socket programming
NemiRathore
Ā 
Np unit2
vamsitricks
Ā 
IPC SOCKET
Sanoj Kumar
Ā 
Unit III IPV6 UDP
sangusajjan
Ā 
Networking lab
Ragu Ram
Ā 
The Considerations for Internet of Things @ 2017
Jian-Hong Pan
Ā 

What's hot (20)

PDF
Wireshark course, Ch 03: Capture and display filters
Yoram Orzach
Ā 
PDF
EKON 25 Python4Delphi_mX4
Max Kleiner
Ā 
PPT
Comparing Cpp And Erlang For Motorola Telecoms Software
l xf
Ā 
PDF
Ekon 25 Python4Delphi_MX475
Max Kleiner
Ā 
DOCX
Lab manual cn-2012-13
Sasi Kala
Ā 
PDF
Sockets
babu4b4u
Ā 
PDF
Netcat cheat sheet_v1
aioudshflaksjdvhv
Ā 
DOC
Networks lab manual ecp62
Basil John
Ā 
PDF
Networking and Go: An Epic Journey
Sneha Inguva
Ā 
PDF
Networking Fundamentals: Transport Protocols (TCP and UDP)
Andriy Berestovskyy
Ā 
PPTX
Part 6 : Internet applications
Olivier Bonaventure
Ā 
PPTX
Sanitizing PCAPs
Jasper Bongertz
Ā 
PPT
ACIT Mumbai - OSI Model
Sleek International
Ā 
PDF
Arduino C maXbox web of things slide show
Max Kleiner
Ā 
PDF
Ch 09 -- ARP & IP Analysis
Yoram Orzach
Ā 
PDF
A closure ekon16
Max Kleiner
Ā 
PDF
Taking Security Groups to Ludicrous Speed with OVS (OpenStack Summit 2015)
Thomas Graf
Ā 
PPTX
Introduction to Remote Procedure Call
Abdelrahman Al-Ogail
Ā 
PDF
Metrics ekon 14_2_kleiner
Max Kleiner
Ā 
PPT
Ds objects and models
Mayank Jain
Ā 
Wireshark course, Ch 03: Capture and display filters
Yoram Orzach
Ā 
EKON 25 Python4Delphi_mX4
Max Kleiner
Ā 
Comparing Cpp And Erlang For Motorola Telecoms Software
l xf
Ā 
Ekon 25 Python4Delphi_MX475
Max Kleiner
Ā 
Lab manual cn-2012-13
Sasi Kala
Ā 
Sockets
babu4b4u
Ā 
Netcat cheat sheet_v1
aioudshflaksjdvhv
Ā 
Networks lab manual ecp62
Basil John
Ā 
Networking and Go: An Epic Journey
Sneha Inguva
Ā 
Networking Fundamentals: Transport Protocols (TCP and UDP)
Andriy Berestovskyy
Ā 
Part 6 : Internet applications
Olivier Bonaventure
Ā 
Sanitizing PCAPs
Jasper Bongertz
Ā 
ACIT Mumbai - OSI Model
Sleek International
Ā 
Arduino C maXbox web of things slide show
Max Kleiner
Ā 
Ch 09 -- ARP & IP Analysis
Yoram Orzach
Ā 
A closure ekon16
Max Kleiner
Ā 
Taking Security Groups to Ludicrous Speed with OVS (OpenStack Summit 2015)
Thomas Graf
Ā 
Introduction to Remote Procedure Call
Abdelrahman Al-Ogail
Ā 
Metrics ekon 14_2_kleiner
Max Kleiner
Ā 
Ds objects and models
Mayank Jain
Ā 
Ad

Viewers also liked (20)

PPTX
Java CRUD Mechanism with SQL Server Database
Dudy Ali
Ā 
PPT
Sockets
sivindia
Ā 
PPT
Networking Java Socket Programming
Mousmi Pawar
Ā 
PPT
Socket Programming Tutorial
Jignesh Patel
Ā 
PPT
Socket Programming - nitish nagar
Nitish Nagar
Ā 
PPTX
Database Introduction - Akses Data dengan SQL Server
Dudy Ali
Ā 
PPT
Networking & Socket Programming In Java
Ankur Agrawal
Ā 
PPTX
Information System Security - Akuntabilitas dan Akses Kontrol
Dudy Ali
Ā 
PPTX
Object Oriented Programming - File Input & Output
Dudy Ali
Ā 
PPTX
Object Oriented Programming - Inheritance
Dudy Ali
Ā 
PPTX
Information System Security - Prinsip Manajemen Keamanan
Dudy Ali
Ā 
PPTX
Socket programming in Java (PPTX)
UC San Diego
Ā 
PDF
Socket programming using java
UC San Diego
Ā 
PPTX
Information System Security - Konsep Manajemen Keamanan
Dudy Ali
Ā 
PPTX
Object Oriented Programming - Value Types & Reference Types
Dudy Ali
Ā 
PDF
Jnp
hj43us
Ā 
PPT
Easy Steps to implement UDP Server and Client Sockets
babak danyal
Ā 
PDF
Java networking programs - theory
Mukesh Tekwani
Ā 
PDF
Netty Cookbook - Table of contents
Trieu Nguyen
Ā 
PPTX
Information System Security - Kriptografi
Dudy Ali
Ā 
Java CRUD Mechanism with SQL Server Database
Dudy Ali
Ā 
Sockets
sivindia
Ā 
Networking Java Socket Programming
Mousmi Pawar
Ā 
Socket Programming Tutorial
Jignesh Patel
Ā 
Socket Programming - nitish nagar
Nitish Nagar
Ā 
Database Introduction - Akses Data dengan SQL Server
Dudy Ali
Ā 
Networking & Socket Programming In Java
Ankur Agrawal
Ā 
Information System Security - Akuntabilitas dan Akses Kontrol
Dudy Ali
Ā 
Object Oriented Programming - File Input & Output
Dudy Ali
Ā 
Object Oriented Programming - Inheritance
Dudy Ali
Ā 
Information System Security - Prinsip Manajemen Keamanan
Dudy Ali
Ā 
Socket programming in Java (PPTX)
UC San Diego
Ā 
Socket programming using java
UC San Diego
Ā 
Information System Security - Konsep Manajemen Keamanan
Dudy Ali
Ā 
Object Oriented Programming - Value Types & Reference Types
Dudy Ali
Ā 
Jnp
hj43us
Ā 
Easy Steps to implement UDP Server and Client Sockets
babak danyal
Ā 
Java networking programs - theory
Mukesh Tekwani
Ā 
Netty Cookbook - Table of contents
Trieu Nguyen
Ā 
Information System Security - Kriptografi
Dudy Ali
Ā 
Ad

Similar to Network Socket Programming with JAVA (20)

PDF
Ł…Ų­Ł…ŲÆ Ł…Ų“Ų§Ų±ŁŠ
maherrrrz
Ā 
PPTX
Chapter 7 : Transport layer
teknetir
Ā 
PDF
CCNAv5 - S1: Chapter 7 - Transport Layer
Vuz Dở HƔi
Ā 
PPTX
Ccna v5-S1-Chapter 7
Hamza Malik
Ā 
PDF
CCNAv5 - S4: Chapter3 Point to-point Connections
Vuz Dở HƔi
Ā 
PDF
OpenDataPlane Project
GlobalLogic Ukraine
Ā 
PPTX
CCNA RS_ITN - Chapter 7
Irsandi Hasan
Ā 
PPTX
Presentation 3 for Students of professordkinney.com
Arnold Derrick Kinney
Ā 
DOCX
Project report,nowrin
NowrinJahanSiam
Ā 
PPTX
cisco-nti-Day18
eyad alaa
Ā 
PPTX
CCNA 1 Routing and Switching v5.0 Chapter 7
Nil Menon
Ā 
PDF
Bangladesh Computer Council Networking Project
MDMusab
Ā 
PPTX
CCNA RS_NB - Chapter 5
Irsandi Hasan
Ā 
PPTX
Project sample internet cafe.pptxffffffgh
kidane16mihret1
Ā 
PDF
Transport Layer Numericals
Manisha Keim
Ā 
PDF
Bcc network connection
MDMusab
Ā 
PDF
Ip tunnelling and_vpn
Rajesh Porwal
Ā 
PPTX
Introduction to netlink in linux kernel (english)
Sneeker Yeh
Ā 
PPT
Client server
maryam1231
Ā 
PPTX
eProsima RPC over DDS - OMG June 2013 Berlin Meeting
Jaime Martin Losa
Ā 
Ł…Ų­Ł…ŲÆ Ł…Ų“Ų§Ų±ŁŠ
maherrrrz
Ā 
Chapter 7 : Transport layer
teknetir
Ā 
CCNAv5 - S1: Chapter 7 - Transport Layer
Vuz Dở HƔi
Ā 
Ccna v5-S1-Chapter 7
Hamza Malik
Ā 
CCNAv5 - S4: Chapter3 Point to-point Connections
Vuz Dở HƔi
Ā 
OpenDataPlane Project
GlobalLogic Ukraine
Ā 
CCNA RS_ITN - Chapter 7
Irsandi Hasan
Ā 
Presentation 3 for Students of professordkinney.com
Arnold Derrick Kinney
Ā 
Project report,nowrin
NowrinJahanSiam
Ā 
cisco-nti-Day18
eyad alaa
Ā 
CCNA 1 Routing and Switching v5.0 Chapter 7
Nil Menon
Ā 
Bangladesh Computer Council Networking Project
MDMusab
Ā 
CCNA RS_NB - Chapter 5
Irsandi Hasan
Ā 
Project sample internet cafe.pptxffffffgh
kidane16mihret1
Ā 
Transport Layer Numericals
Manisha Keim
Ā 
Bcc network connection
MDMusab
Ā 
Ip tunnelling and_vpn
Rajesh Porwal
Ā 
Introduction to netlink in linux kernel (english)
Sneeker Yeh
Ā 
Client server
maryam1231
Ā 
eProsima RPC over DDS - OMG June 2013 Berlin Meeting
Jaime Martin Losa
Ā 

More from Dudy Ali (20)

PDF
Understanding COM+
Dudy Ali
Ā 
PDF
Distributed Application Development (Introduction)
Dudy Ali
Ā 
PPTX
Review Materi ASP.NET
Dudy Ali
Ā 
PPTX
XML Schema Part 2
Dudy Ali
Ā 
PPTX
XML Schema Part 1
Dudy Ali
Ā 
PPTX
Rendering XML Document
Dudy Ali
Ā 
PPTX
Pengantar XML
Dudy Ali
Ā 
PPTX
Pengantar XML DOM
Dudy Ali
Ā 
PPTX
Pengantar ADO.NET
Dudy Ali
Ā 
PPTX
Database Connectivity with JDBC
Dudy Ali
Ā 
PPTX
XML - Displaying Data ith XSLT
Dudy Ali
Ā 
PPTX
Algorithm & Data Structure - Algoritma Pengurutan
Dudy Ali
Ā 
PPTX
Algorithm & Data Structure - Pengantar
Dudy Ali
Ā 
PPTX
Object Oriented Programming - Constructors & Destructors
Dudy Ali
Ā 
PPTX
Object Oriented Programming - Abstraction & Encapsulation
Dudy Ali
Ā 
PPTX
Web Programming Syaria - Pengenalan Halaman Web
Dudy Ali
Ā 
PPTX
Web Programming Syaria - PHP
Dudy Ali
Ā 
PPTX
Software Project Management - Project Management Knowledge
Dudy Ali
Ā 
PPTX
Software Project Management - Proses Manajemen Proyek
Dudy Ali
Ā 
PPTX
Software Project Management - Pengenalan Manajemen Proyek
Dudy Ali
Ā 
Understanding COM+
Dudy Ali
Ā 
Distributed Application Development (Introduction)
Dudy Ali
Ā 
Review Materi ASP.NET
Dudy Ali
Ā 
XML Schema Part 2
Dudy Ali
Ā 
XML Schema Part 1
Dudy Ali
Ā 
Rendering XML Document
Dudy Ali
Ā 
Pengantar XML
Dudy Ali
Ā 
Pengantar XML DOM
Dudy Ali
Ā 
Pengantar ADO.NET
Dudy Ali
Ā 
Database Connectivity with JDBC
Dudy Ali
Ā 
XML - Displaying Data ith XSLT
Dudy Ali
Ā 
Algorithm & Data Structure - Algoritma Pengurutan
Dudy Ali
Ā 
Algorithm & Data Structure - Pengantar
Dudy Ali
Ā 
Object Oriented Programming - Constructors & Destructors
Dudy Ali
Ā 
Object Oriented Programming - Abstraction & Encapsulation
Dudy Ali
Ā 
Web Programming Syaria - Pengenalan Halaman Web
Dudy Ali
Ā 
Web Programming Syaria - PHP
Dudy Ali
Ā 
Software Project Management - Project Management Knowledge
Dudy Ali
Ā 
Software Project Management - Proses Manajemen Proyek
Dudy Ali
Ā 
Software Project Management - Pengenalan Manajemen Proyek
Dudy Ali
Ā 

Recently uploaded (20)

PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
Ā 
PDF
Event Presentation Google Cloud Next Extended 2025
minhtrietgect
Ā 
PDF
BLW VOCATIONAL TRAINING SUMMER INTERNSHIP REPORT
codernjn73
Ā 
PDF
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
Ā 
PDF
Using Anchore and DefectDojo to Stand Up Your DevSecOps Function
Anchore
Ā 
PPTX
AI and Robotics for Human Well-being.pptx
JAYMIN SUTHAR
Ā 
PPTX
IoT Sensor Integration 2025 Powering Smart Tech and Industrial Automation.pptx
Rejig Digital
Ā 
PDF
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
Ā 
PDF
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
Ā 
PDF
Orbitly Pitch Deck|A Mission-Driven Platform for Side Project Collaboration (...
zz41354899
Ā 
PDF
A Strategic Analysis of the MVNO Wave in Emerging Markets.pdf
IPLOOK Networks
Ā 
PDF
How-Cloud-Computing-Impacts-Businesses-in-2025-and-Beyond.pdf
Artjoker Software Development Company
Ā 
PDF
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
Ā 
PDF
Unlocking the Future- AI Agents Meet Oracle Database 23ai - AIOUG Yatra 2025.pdf
Sandesh Rao
Ā 
PDF
A Day in the Life of Location Data - Turning Where into How.pdf
Precisely
Ā 
PPTX
Coupa-Overview _Assumptions presentation
annapureddyn
Ā 
PDF
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
Ā 
PDF
Cloud-Migration-Best-Practices-A-Practical-Guide-to-AWS-Azure-and-Google-Clou...
Artjoker Software Development Company
Ā 
PDF
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
Ā 
PDF
Research-Fundamentals-and-Topic-Development.pdf
ayesha butalia
Ā 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
Ā 
Event Presentation Google Cloud Next Extended 2025
minhtrietgect
Ā 
BLW VOCATIONAL TRAINING SUMMER INTERNSHIP REPORT
codernjn73
Ā 
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
Ā 
Using Anchore and DefectDojo to Stand Up Your DevSecOps Function
Anchore
Ā 
AI and Robotics for Human Well-being.pptx
JAYMIN SUTHAR
Ā 
IoT Sensor Integration 2025 Powering Smart Tech and Industrial Automation.pptx
Rejig Digital
Ā 
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
Ā 
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
Ā 
Orbitly Pitch Deck|A Mission-Driven Platform for Side Project Collaboration (...
zz41354899
Ā 
A Strategic Analysis of the MVNO Wave in Emerging Markets.pdf
IPLOOK Networks
Ā 
How-Cloud-Computing-Impacts-Businesses-in-2025-and-Beyond.pdf
Artjoker Software Development Company
Ā 
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
Ā 
Unlocking the Future- AI Agents Meet Oracle Database 23ai - AIOUG Yatra 2025.pdf
Sandesh Rao
Ā 
A Day in the Life of Location Data - Turning Where into How.pdf
Precisely
Ā 
Coupa-Overview _Assumptions presentation
annapureddyn
Ā 
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
Ā 
Cloud-Migration-Best-Practices-A-Practical-Guide-to-AWS-Azure-and-Google-Clou...
Artjoker Software Development Company
Ā 
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
Ā 
Research-Fundamentals-and-Topic-Development.pdf
ayesha butalia
Ā 

Network Socket Programming with JAVA

  • 1. Q7M1 – SC Dudy Fathan Ali S.Kom Network Socket Programming Q7M1 Dudy Fathan Ali, S.Kom (DFA) 2017 CEP - CCIT Fakultas Teknik Universitas Indonesia
  • 2. Consider this scenario.. Q7M1 – SC Dudy Fathan Ali S.Kom Hello, I want a pizza. Guys, bob wants a pizza! Bob Pizza Store
  • 3. Consider this scenario.. Q7M1 – SC Dudy Fathan Ali S.Kom Pizza Store Standard Operational Procedure
  • 4. Hmm.. Q7M1 – SC Dudy Fathan Ali S.Kom
  • 5. Client/Server Architecture Q7M1 – SC Dudy Fathan Ali S.Kom Bob [Client] Pizza Store [Server] The client places a request or order to the server. The server processes the request of the client The communication between the client and the server is usually through a network. The Client/Server model is an application development architecture designed to separate the presentation of data from its internal processing and storage.
  • 6. Client/Server Architecture Q7M1 – SC Dudy Fathan Ali S.Kom Pizza Store The processing that is done by the server is hidden from the client.
  • 7. Client/Server Architecture Q7M1 – SC Dudy Fathan Ali S.Kom Steve Bob John One server can service multiple clients.
  • 8. Client/Server Architecture Q7M1 – SC Dudy Fathan Ali S.Kom The server and the client are not necessarily hardware components. They can be programs working on the same machine or on different machines.
  • 9. Internet Protocol Q7M1 – SC Dudy Fathan Ali S.Kom The Internet Protocol (IP) is the principal communications protocol in the Internet protocol suite for relaying datagrams across network boundaries. Its routing function enables internetworking, and essentially establishes the Internet. -- Source: wikipedia.org -- Source: google.com
  • 10. Internet Protocol Q7M1 – SC Dudy Fathan Ali S.Kom implicit rules in conversation?
  • 11. Internet Protocol Q7M1 – SC Dudy Fathan Ali S.Kom o Data is sent from one machine to another in form of packets. o Rules govern packaging of data into packets, speed of transmission, and reassembling of data into its original form. o These rules are called network protocols. Communication rules between computers
  • 12. IP Address & Port Q7M1 – SC Dudy Fathan Ali S.Kom
  • 13. IP Address & Port Q7M1 – SC Dudy Fathan Ali S.Kom The TCP protocol requires two data items: the IP address and the port number. 172.17.8.192 : 80 IP Address Port o Well-known ports o Registered ports o Dynamic/Private ports
  • 14. IP Address & Port Q7M1 – SC Dudy Fathan Ali S.Kom IP Addresses of Popular Websites
  • 15. Sockets Q7M1 – SC Dudy Fathan Ali S.Kom Sockets are used to handle the communication links between applications over the network. Further communication between the client and the server is through the socket. -- Source: NIIT Courseware Q7M1
  • 16. Java Classes for Network Programming Q7M1 – SC Dudy Fathan Ali S.Kom o The java.net package of the Java programming language contains classes and interfaces that provide support for networking. o Networking classes contain methods to perform tasks, such as opening and closing a connection to remote machine, sending and receiving data packets and accessing resources on the Web.
  • 17. Java Classes for Network Programming Q7M1 – SC Dudy Fathan Ali S.Kom Classes of the java.net Package: o DatagramPacket o Represents a datagram packet. o DatagramSocket o Represents a datagram socket object that can send and receive datagram packets. o MulticastSocket o Creates a multicast datagram socket object that is used to send and receive datagram packets to groups. o InetAddress o Represents an IP address. o ServerSocket o Represents a TCP/IP server socket object that receives connection requests from the clients.
  • 18. Java Classes for Network Programming Q7M1 – SC Dudy Fathan Ali S.Kom The InetAddress Class: o Represents an IP address. o Contains the following static methods to initialize InetAddress objects: o public static InetAddress getLocalHost() o public static InetAddress getByName(String host) o public static InetAddress[] getAllByName(String host)
  • 19. Java Classes for Network Programming Q7M1 – SC Dudy Fathan Ali S.Kom The non-static methods of the InetAddress class are: o public boolean equals(Object obj) o public byte[] getAddress() o public String getHostAddress() o public String toString()
  • 20. Java Classes for Network Programming Q7M1 – SC Dudy Fathan Ali S.Kom Code Example: Result: Returns an InetAddress object that contains the IP address of the local computer. Returns the IP address of the InetAddress object as a String.
  • 21. TCP vs UDP Q7M1 – SC Dudy Fathan Ali S.Kom
  • 22. TCP vs UDP Q7M1 – SC Dudy Fathan Ali S.Kom
  • 23. Creating Application Using UDP Q7M1 – SC Dudy Fathan Ali S.Kom o UDP is a fast, connectionless, and unreliable protocol. o UDP sockets use UDP protocol for communication over a network. o The java.net package provides the following two classes that enable you to implement UDP sockets in a Java application: o DatagramPacket class o DatagramSocket class o The DatagramPacket object is a data container that consists of datagram packets that are sent or received over the network. o The constructor used to initialize DatagramPacket objects are: o public DatagramPacket( byte[] buffer, int buffer_length) o public DatagramPacket( byte[] buffer, int buffer_length, InetAddress address, int port)
  • 24. Creating Application Using UDP Q7M1 – SC Dudy Fathan Ali S.Kom o DatagramSocket class encapsulates the functionality to handle DatagramPacket objects. o The constructors used to initialize DatagramSocket object are: o public DatagramSocket() o public DatagramSocket(int port) o public DatagramSocket(int port, InetAddress address)
  • 25. Creating Application Using UDP Q7M1 – SC Dudy Fathan Ali S.Kom Code Example [DataSender]:
  • 26. Creating Application Using UDP Q7M1 – SC Dudy Fathan Ali S.Kom Code Example [DataReceiver]:
  • 27. Demonstration-Implementing UDP Q7M1 – SC Dudy Fathan Ali S.Kom Create a Client/Server application where the server can broadcast messages to all the clients of 233.0.0.1 group.
  • 28. Q7M1 – SC Dudy Fathan Ali S.Kom Thank You! Dudy Fathan Ali, S.Kom [email protected]