The ClientServer Paradigm - PowerPoint PPT Presentation

1 / 21
About This Presentation
Title:

The ClientServer Paradigm

Description:

It is the basis of all distributed computing paradigms at a higher ... DatagramPacket theEcho = new DatagramPacket(buffer,len, cAddr, cPort); ds.send(theEcho) ... – PowerPoint PPT presentation

Number of Views:25
Avg rating:3.0/5.0
Slides: 22
Provided by: ise2
Category:

less

Transcript and Presenter's Notes

Title: The ClientServer Paradigm


1
The Client-Server Paradigm

2
Introduction
  • The Client-Server paradigm is the most prevalent
    model for distributed computing protocols.
  • It is the basis of all distributed computing
    paradigms at a higher level of abstraction.
  • It is service-oriented, and employs a
    request-response protocol.

3
The Client-Server Paradigm
  • A server process, running on a server host,
    provides access to a service.
  • A client process, running on a client host,
    accesses the service via the server process.
  • The interaction of the process proceeds according
    to a protocol.

4
Client-server applications and services
  • An application based on the client-server
    paradigm is a client-server application.
  • On the Internet, many services are Client-server
    applications. These services are often known by
    the protocol that the application implements.
  • Well known Internet services include HTTP, FTP,
    DNS, finger, gopher, etc.
  • User applications may also be built using the
    client-server paradigm.

5
(No Transcript)
6
Connectionless Server
  • A connectionless server accepts one request
    at a time from any client, processes the request,
    and sends the response to the requestor.

7
Connection-Oriented Client-Server applications
  • A client-server application can be either
    connection-oriented or connectionless.
  • In a connection-oriented client-server
    application
  • The server is passive it listens and waits for
    connection requests from clients, and accepts one
    connection at a time.
  • A client issues a connection request, and waits
    for its connection to be accepted.
  • Once a server accepts a connection, it waits for
    a request from the client.
  • When a client is connected to the server, it
    issues a request and waits for the response.
  • When a server receives a request, it processes
    the request and sends a response, then wait for
    the next request, if any.
  • The client receives the request and processes it.
    If there are further requests, the process
    repeats itself until the protocol is consumated.

8
Connectionless Echo Server
  • DatagramSocket ds new DatagramSocket(port)
  • while (true)
  • try
  • // create a new datagram packet
  • byte buffer new byteMAXLEN
  • DatagramPacket dp new
    DatagramPacket(buffer, MAXLEN)
  • ds.receive(dp)
  • len dp.getLength()
  • cAddr dp.getAddress()
  • cPort dp.getPort()
  • String s new String(dp.getData(), 0,
    len)
  • System.out.println(dp.getAddress() "
    at port "
  • dp.getPort() " says " s)
  • // create a datagram packet to send to
    client
  • DatagramPacket theEcho new
    DatagramPacket(buffer,len,
  • cAddr, cPort)
  • ds.send(theEcho)
  • // end try

9
The Basic Connection-Oriented Client-Server Model
10
Concurrent, Connection-Oriented Server
  • A connection-oriented server services one client
    at a time.
  • If the duration of each client session is
    significant, then the latency or turnaround time
    of a client request becomes unacceptable if the
    number of concurrent client processes is large.
  • To improve the latency, a server process spawns a
    child process or child thread to process the
    protocol for each client. Such a server is
    termed a concurrent server, compared to an
    iterative server.

11
Concurrent, connection-oriented server - 2
  • A concurrent server uses its main thread to
    accept connections, and spawns a child thread to
    process the protocol for each client.
  • Clients queue for connection, then are served
    concurrently. The concurrency reduces latency
    significantly.

12
Connection-oriented server latency analysis
  • For a given server S, let Tc be the expected time
    that S takes to accept a connection, and Tp be
    the expected time S takes to process the protocol
    for a client.
  • Further assume that the expected number of
    concurrent clients requiring the service of S is
    N.

13
Connection-oriented Daytime Server
  • theServer new ServerSocket(thePort)
  • p new PrintWriter(System.out)
  • try
  • p.println("Echo Server now in business on
    port "
  • thePort )
  • p.flush()
  • theConnection theServer.accept()
  • // read a line from the client
  • theInputStream new BufferedReader
  • (new InputStreamReader
    (theConnection.getInputStream()))
  • p new PrintWriter(theConnection.getOutp
    utStream())
  • while (!done)
  • theLine theInputStream.readLine()
  • if (theLine null) done true
  • else
  • p.println(theLine)
  • p.flush()

Connection acceptance
Protocol processing
14
Connection-oriented Concurrent DayTime Server
ConcurrentDaytimeServer.java DaytimeServerThread.j
ava
  • theServer new ServerSocket(thePort)
  • p new PrintWriter(System.out)
  • try
  • p.println("dayTime Server now in business
    on port "
  • thePort )
  • p.flush()
  • while (true)
  • theConnection theServer.accept()
  • daytimeServerThread theThread new
    daytimeServerThread(theConnection)
  • theThread.start()
  • public class daytimeServerThread extends Thread
  • Socket theConnection
  • public daytimeServerThread(Socket s)
  • theConnection s
  • public void run()
  • try
  • PrintWriter p
  • p new PrintWriter(theConnection.getOutp
    utStream())
  • p.println(new Date())
  • p.flush()
  • theConnection.close()
  • catch (IOException e)
  • System.err.println(e)
  • // end try
  • // end thread class

15
Connection-oriented Echo Server
  • public class echoServer
  • public static void main(String args)
  • ServerSocket theServer
  • int thePort
  • Socket theConnection
  • PrintWriter p
  • BufferedReader theInputStream
  • String theLine
  • boolean done false
  • theServer new ServerSocket(thePort)
  • p new PrintWriter(System.out)
  • try
  • theConnection theServer.accept()
  • // read a line from the client
  • theInputStream new BufferedReader
  • (new InputStreamReader
    (theConnection.getInputStream()))
  • p new PrintWriter(theConnection.getOutputS
    tream())
  • while (!done)
  • theLine theInputStream.readLine()
  • if (theLine null) done true
  • else
  • p.println(theLine)
  • p.flush()
  • // end if
  • //end while
  • theConnection.close()
  • // end try

16
Concurrent Echo Server
  • See ConcurrentEchoServer.java
  • See EchoServerThread.java

17
Stateful server
  • A stateful server maintain stateful information
    on each active client.
  • Stateful information can reduce the data
    exchanged, and thereby the response time.

18
Stateful vs. Stateless server
  • Stateless server is straightforward to code.
  • Stateful server is harder to code, but the state
    information maintained by the server can reduce
    the data exchanged, and allows enhancements to a
    basic service.
  • Maintaining stateful information is difficult in
    the presence of failures.

19
Stateful vs. stateless server
  • In actual implementation, a server may be
  • Stateless
  • Stateful
  • A hybrid, wherein the state data is distributed
    on both the server-side and the client-side.
  • Which type of server is chosen is a design issue.

20
A client can contact multiple servers
  • A process may require the service of multiple
    servers. For example, it may obtain a timestamp
    from a daytime server, data from a database
    server, and a file from a file server.

21
Middleware
  • A process can serve as a intermediary, or
    middleware, between a client and a server.
Write a Comment
User Comments (0)
About PowerShow.com