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
PPT
Socket Programming
PDF
Socket programming
PPT
Np unit2
PPTX
IPC SOCKET
PPT
Unit III IPV6 UDP
PDF
Networking lab
PDF
The Considerations for Internet of Things @ 2017
Socket Programming using Java
Socket Programming
Socket programming
Np unit2
IPC SOCKET
Unit III IPV6 UDP
Networking lab
The Considerations for Internet of Things @ 2017

What's hot (20)

PDF
Wireshark course, Ch 03: Capture and display filters
PDF
EKON 25 Python4Delphi_mX4
PPT
Comparing Cpp And Erlang For Motorola Telecoms Software
PDF
Ekon 25 Python4Delphi_MX475
DOCX
Lab manual cn-2012-13
PDF
Sockets
PDF
Netcat cheat sheet_v1
DOC
Networks lab manual ecp62
PDF
Networking and Go: An Epic Journey
PDF
Networking Fundamentals: Transport Protocols (TCP and UDP)
PPTX
Part 6 : Internet applications
PPTX
Sanitizing PCAPs
PPT
ACIT Mumbai - OSI Model
PDF
Arduino C maXbox web of things slide show
PDF
Ch 09 -- ARP & IP Analysis
PDF
A closure ekon16
PDF
Taking Security Groups to Ludicrous Speed with OVS (OpenStack Summit 2015)
PPTX
Introduction to Remote Procedure Call
PDF
Metrics ekon 14_2_kleiner
PPT
Ds objects and models
Wireshark course, Ch 03: Capture and display filters
EKON 25 Python4Delphi_mX4
Comparing Cpp And Erlang For Motorola Telecoms Software
Ekon 25 Python4Delphi_MX475
Lab manual cn-2012-13
Sockets
Netcat cheat sheet_v1
Networks lab manual ecp62
Networking and Go: An Epic Journey
Networking Fundamentals: Transport Protocols (TCP and UDP)
Part 6 : Internet applications
Sanitizing PCAPs
ACIT Mumbai - OSI Model
Arduino C maXbox web of things slide show
Ch 09 -- ARP & IP Analysis
A closure ekon16
Taking Security Groups to Ludicrous Speed with OVS (OpenStack Summit 2015)
Introduction to Remote Procedure Call
Metrics ekon 14_2_kleiner
Ds objects and models
Ad

Viewers also liked (20)

PPTX
Java CRUD Mechanism with SQL Server Database
PPT
Sockets
PPT
Networking Java Socket Programming
PPT
Socket Programming Tutorial
PPT
Socket Programming - nitish nagar
PPTX
Database Introduction - Akses Data dengan SQL Server
PPT
Networking & Socket Programming In Java
PPTX
Information System Security - Akuntabilitas dan Akses Kontrol
PPTX
Object Oriented Programming - File Input & Output
PPTX
Object Oriented Programming - Inheritance
PPTX
Information System Security - Prinsip Manajemen Keamanan
PPTX
Socket programming in Java (PPTX)
PDF
Socket programming using java
PPTX
Information System Security - Konsep Manajemen Keamanan
PPTX
Object Oriented Programming - Value Types & Reference Types
PDF
Jnp
PPT
Easy Steps to implement UDP Server and Client Sockets
PDF
Java networking programs - theory
PDF
Netty Cookbook - Table of contents
PPTX
Information System Security - Kriptografi
Java CRUD Mechanism with SQL Server Database
Sockets
Networking Java Socket Programming
Socket Programming Tutorial
Socket Programming - nitish nagar
Database Introduction - Akses Data dengan SQL Server
Networking & Socket Programming In Java
Information System Security - Akuntabilitas dan Akses Kontrol
Object Oriented Programming - File Input & Output
Object Oriented Programming - Inheritance
Information System Security - Prinsip Manajemen Keamanan
Socket programming in Java (PPTX)
Socket programming using java
Information System Security - Konsep Manajemen Keamanan
Object Oriented Programming - Value Types & Reference Types
Jnp
Easy Steps to implement UDP Server and Client Sockets
Java networking programs - theory
Netty Cookbook - Table of contents
Information System Security - Kriptografi
Ad

Similar to Network Socket Programming with JAVA (20)

PPTX
IPT Chapter 2 Web Services and Middleware - Dr. J. VijiPriya
PPTX
5_6278455688045789623.pptx
PPTX
Networking in Java
PDF
Networking Basics1ofjavaprogramming.pptx.pdf
PPT
Md13 networking
PDF
Unit 6 - Netwohhhhhddddrking in Java.pdf
PPT
Network programming in Java
PPT
Network programming in Java
PPT
Network Programming in Java
PPTX
Chapter 4--converted.pptx
PPTX
PPTX
Network programming in java - PPT
PDF
Packet Guide SONET/SDH
PPTX
Java Network Programming.pptx
PDF
28 networking
PPTX
Java socket programming
PPTX
Advance Java-Network Programming
PDF
Ismail TCP IP.pdf
PDF
Ismail TCP IP.pdf
PPT
tcpip.ppt
IPT Chapter 2 Web Services and Middleware - Dr. J. VijiPriya
5_6278455688045789623.pptx
Networking in Java
Networking Basics1ofjavaprogramming.pptx.pdf
Md13 networking
Unit 6 - Netwohhhhhddddrking in Java.pdf
Network programming in Java
Network programming in Java
Network Programming in Java
Chapter 4--converted.pptx
Network programming in java - PPT
Packet Guide SONET/SDH
Java Network Programming.pptx
28 networking
Java socket programming
Advance Java-Network Programming
Ismail TCP IP.pdf
Ismail TCP IP.pdf
tcpip.ppt

More from Dudy Ali (20)

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

Recently uploaded (20)

PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPTX
Spectroscopy.pptx food analysis technology
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPT
Teaching material agriculture food technology
PDF
KodekX | Application Modernization Development
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
20250228 LYD VKU AI Blended-Learning.pptx
Spectroscopy.pptx food analysis technology
Dropbox Q2 2025 Financial Results & Investor Presentation
Mobile App Security Testing_ A Comprehensive Guide.pdf
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Building Integrated photovoltaic BIPV_UPV.pdf
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
MYSQL Presentation for SQL database connectivity
Per capita expenditure prediction using model stacking based on satellite ima...
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
The Rise and Fall of 3GPP – Time for a Sabbatical?
Teaching material agriculture food technology
KodekX | Application Modernization Development
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Advanced methodologies resolving dimensionality complications for autism neur...
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Digital-Transformation-Roadmap-for-Companies.pptx

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 dudy.fathan@eng.ui.ac.id