CLIENT-SERVER ARCHITECTURE

Nitya Priya
5 min readDec 30, 2019

--

Client-server architecture is a computing model in which the server hosts, delivers and manages most of the resources and services to be consumed by the client. This type of architecture has one or more client computers connected to a central server over a network or internet connection. This system shares computing resources. The client-server architecture is also termed as a network-computing structure because every request and their associated services are distributed over a network. In the client-server architecture, when the client computer sends a request for data to the server through the internet, the server accepts the requested, process it and deliver the data packets requested back to the client. One special feature is that the server computer has the potential to manage numerous clients at the same time. Also, a single client can connect to numerous servers at a single timestamp, where each server provides a different set of services to that specific client. Client-server architecture is a producer-consumer computing architecture where the server acts as the producer and the client as a consumer. The server houses and provides high-end, computing-intensive services to the client on demand. These services can include application access, storage, file sharing, printer access and/or direct access to the server’s raw computing power.

  • The client-server characteristic describes the relationship of cooperating programs in an application.
  • Mainly implemented and popular formats are done in XML and JSON.

Client-Server communication:

Clients and servers exchange messages in a request–response messaging pattern. The client sends a request, and the server returns a response. This exchange of messages is an example of inter-process communication. To communicate, the computers must have a common language, and they must follow rules so that both the client and the server know what to expect. The language and rules of communication are defined in a communications protocol. All client-server protocols operate in the application layer. The application layer protocol defines the basic patterns of the dialogue. A server may receive requests from many distinct clients in a short period of time. A computer can only perform a limited number of tasks at any moment, and relies on a scheduling system to prioritise incoming requests from clients to accommodate them. To prevent abuse and maximise availability, server software may limit the availability to clients. Denial of service attacks are designed to exploit a server’s obligation to process requests by overloading it with excessive request rates. Encryption should be applied for sensitive information.

Simple client-server connection program:

A Java program for a Client:

import java.net.*;

import java.io.*;

public class Client {

// initialize socket and input output streams

private Socket socket = null;

private DataInputStream input = null;

private DataOutputStream out = null;

// constructor to put ip address and port

public Client(String address, int port) {

// establish a connection

try{

socket = new Socket(address, port);

System.out.println(“Connected”);

// takes input from terminal

input = new DataInputStream(System.in);

// sends output to the socket

out = new DataOutputStream(socket.getOutputStream());

}

catch(UnknownHostException u) {

System.out.println(u); }

catch(IOException i) {

System.out.println(i); }

// string to read message from input

String line = “”;

// keep reading until “Over” is input

while (!line.equals(“Over”)) {

try{

line = input.readLine();

out.writeUTF(line); }

catch(IOException i) {

System.out.println(i); }

}

// close the connection

try {

input.close();

out.close();

socket.close(); }

catch(IOException i) {

System.out.println(i); }

}

public static void main(String args[]) {

Client client = new Client(“127.0.0.1”, 5000); }

}

A Java program for a Server

import java.net.*;

import java.io.*;

public class Server {

//initialize socket and input stream

private Socket socket = null;

private ServerSocket server = null;

private DataInputStream in = null;

// constructor with port

public Server(int port) {

// starts server and waits for a connection

try {

server = new ServerSocket(port);

System.out.println(“Server started”);

System.out.println(“Waiting for a client …”);

socket = server.accept();

System.out.println(“Client accepted”);

// takes input from the client socket

in = new DataInputStream(new BufferedInputStream(socket.getInputStream()));

String line = “”;

// reads message from client until “Over” is sent

while (!line.equals(“Over”)) {

try{

line = in.readUTF();

System.out.println(line); }

catch(IOException i) {

System.out.println(i); }

}

System.out.println(“Closing connection”);

// close connection

socket.close();

in.close();

}

catch(IOException i) {

System.out.println(i); }

}

public static void main(String args[]) {

Server server = new Server(5000); }

}

(first run server, next client)

This computing model is especially effective when clients and the server each have distinct tasks that they routinely perform.

Example: In hospital data processing, for example, a client computer can be running an application program for entering patient information while the server computer is running another program that manages the database in which the information is permanently stored.

Three-tier client-server architecture:

The traditional client/server architecture involves two levels, a client level and a server level. Another common design of client/server system uses three tiers:

  • A client that interacts with the user
  • An application server that contains the business logic of the application
  • A resource manager that stores data

Characteristics:

  • Client and server machines need different amount of hardware and software resources.
  • Client and server machines may belong to different vendors.
  • Horizontal scalability (increase of the client machines) and vertical scalability (migration to a more powerful server or to a multi server solution)
  • A client or server application interacts directly with a transport layer protocol to establish communication and to send or receive information.
  • The transport protocol then uses lower layer protocols to send or receive individual messages. Thus, a computer needs a complete stack of protocols to run either a client or a server.
  • A single server-class computer can offer multiple services at the same time; a separate server program is needed for each service.

Client-server vs peer to peer:

  • In the client-server architecture, there are designated clients that request for services and servers that provide services, but in peer to peer systems, peers act as both service providers and service consumers.
  • Client-server systems require central file server and they are expensive to implement than peer to peer systems.
  • In the client-server system, a dedicated file server provides level of access to the clients, providing better security than peer to peer systems where security is handled by the end users.
  • Peer to peer networks suffer in performance as the number of nodes increase, but client-server systems are more stable and could be scaled as much as you need.
  • In distributed architecture, one or more dedicated machines are used only as server while all the other machines are used as clients. In this scenario, clients can communicate via server. In this mode, client initiates communications. Client issues request to a server. Server replies or performs some service.
  • In peer to peer architecture, each of the host or instance of application program can function as both client and server simultaneously. Both of them has equivalent responsibilities and status. In this mode, any participant can initiate communication. Any device can generate a request. Any device may provide a response.

Advantages:

  • Improved data sharing
  • Integration of services
  • Shared resources amongst different platforms
  • Inter-operation of data
  • Data processing capability despite the location
  • Easy maintenance
  • Security

Disadvantages:

  • Overloaded servers
  • Impact of centralized architecture

--

--