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.
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
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.
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)
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.