Client-Server architecture and Protocols

Client Server Architecture

Client-Server architecture is a minimum architecture to prepare web applications.

In Client – Server Architecture , there are 3 main components.

  1. Client
  2. Protocol
  3. Server

Client

Client is a Browser, in Client-Server applications, Client is able to send request data to the Server and it is able to get response data from the Server.

In Web Applications, to send requests from the client browser we have to provide a string in the client browser’s address bar, here the provided String data at the address bar is called URI.

URI[Uniform Resource Identifier] is a String specification provided at the client address bar, it can be used to refer to a particular resource available at the Server side application.

Types of URIs

There are two types of URIs.

  1. URN
  2. URL

URN vs URL

What is the difference between URN and URL?

URN is a string data provided at the client address bar to refer to a particular server side resource available at the Server machine through the resources logical name.

Note: In the case of Servlets, logical Name is the name provided along with <servlet-name> tag in web.xml file.

Note: Almost all the Servers are not supporting URN notations.

URL is a String data provided at the client address bar to refer to a particular server side resource through its locator or url pattern.

Note: In the case of Servlets, url pattern is a pattern name provided at the <url-pattern> tag in the web.xml file.

Note: Almost all the Servers are supporting URL notations.

URL syntax

Protocol://ServerIPAddress:ServerPortNumber/ApplName/resourceName?QueryString

http://98.67.58.65:8080/loginapp/login?uname=abc&upwd=xyz

http://98.67.58.65:1010/regapp/reg?fname=abc&lname=xyz&addr=Hyd

Note: If the Server software is available at the same client machine then it is possible to provide “localhost” in place of Server IP address in the URL.

http://localhost:8080/loginapp/login?uname=abc&upwd=xyz

http://localhost:1010/regapp/reg?fname=abc&lname=xyz&addr=Hyd

IP Address and Port number

What is the difference between IP Address and Port Number?

IP Address is an unique identity provided to each and every system existing in the Network and it would be provided by the Network Manager at the time of Network configuration.

Port Number is an unique identity provided to each and every process being executed in a single computer and it would be provided by the Local Operating System.

Query String

What is Query String and what is its requirement in Web applications?

Query String is the collection of Key-Value pairs, it can be used to provide input data to the Server side resources in order to perform Server side action.

http://98.67.58.65:8080/loginapp/login?uname=abc&upwd=xyz

Where uname=abc and upwd=xyz is the Query String.

http://98.67.58.65:1010/regapp/reg?fname=abc&lname=xyz&addr=Hyd

Where fname=abc, lname=xyz, addr=Hyd is Query String.


Protocols

Protocol is a set of rules and regulations to carry data from one machine to another machine over the network.

The role of the protocol in Client-Server applications is to carry request data from Client machine to the Server machine and to carry response data from Server machine to the client machine.

EX: Http, Tcp, IP, SMTP, FTP,…

HTTP Protocol

In general, we will use the Http protocol in web application why?

In web applications, we need a protocol, it must be 

  1. Connectionless
  2. Stateless
  3. Compatible With Hyper Text data

Where the Connection less protocol is a protocol, it must not have any physical connections, it must have a virtual connection.

Where the Stateless protocol is a protocol, it must maintain the present request data only and it must not maintain the previous requests data.

In general, in web applications, both request data and response data will be provided in the form of hypertext data, so we need a protocol that must be compatible with the hypertext data. 

Out of all the protocols, only the Http protocol supports all the above features , so HTTP protocol is required in the web applications.

Q) How does the Http protocol maintain its Stateless feature?

In Web applications, when we submit a request from Client to the Server, Protocol will take the request and the Protocol will perform the following actions.

  1. Protocol will establish a virtual connection between Client and Server on the basis of the provided Server IP address and Server Port Number.
  2. Protocol will create a Request Format that contains Header part and Body part, where the Header part is able to manage the request headers data like Browser name, Browser Supported Encoding mechanisms,Browser Supported zipping formats, Browsers Locale, Request URI,….and the Body Part is able to manage the request parameters data, where the request parameters data is the data provided by the Users at client browser in the USer forms.
  1. Protocol will carry the generated Request Format to the Server Machine.

At Server Machine, Server Software will take the request data from the Request Format , Server Software will identify the Server side application and the Server side resource and Server software will execute the Server side resource and generate the required response to the CLient.

When the response is sent to the Client, Protocol will take the response and the Protocol will perform the following actions.

  1. Protocol Will create a Response Format that contains Header part and Body part, where the Header part is able to provide the metadata of the response like type of the response, size of the response,…. And the Body is able to manage the actual dynamic response.
  2. Protocol will carry Response Format to the CLient Machine.

Note: Client Browser will take the response from the Response format and it will display the generated response to the USers.

  1. Protocol will terminate the connection between Client and Server, with this the protocol will remove the present request data .

IN Web applications, Protocol is able to manage the present request data up to the connection’s existence, once the connection is terminated Protocol will remove the present request data from its memory, it will not be available to the next requests.

The above nature of the Http protocol is Stateless nature.

Note: In the applications like E-Commerce applications, Online Shopping applications, Online Banking applications,…. It is mandatory to manage the clients previous request data at the time of processing later requests, for this we have to use a set of mechanisms explicitly called “Session Tracking Mechanisms”. 

In web applications, HTTP Protocol is able to provide flexibility to send different types of requests from Client to the Server.


HTTP Methods

To send different types of requests from CLient to the Server, Http protocol has provided a set of methods internally called “Http Methods”.

As per the Http1.0 version:

  1. GET
  2. POST
  3. HEAD

As per the Http 2.0 version:

  1. OPTIONS
  2. TRACE
  3. PUT
  4. DELETE

GET vs POST

  1. GET Request is a default request in web applications.

POST Request is not a default request type in web applications.

  1.  GET Request does not have the BODY part in the Request Format.

POST Request has the BODY part in the Request Format.

  1.  GET request is able to carry less data from Client to Server, because GET request does not have BODY part, so the request data will be transferred to the Server through the Request Format header part, where the Request Format header part will have the memory limitations.

POST request is able to carry more data from Client to Server, because POST request has the BODY part in the Request Format, POST request does not have any memory limitations.  

  1. GET Request will provide less security for the Data, where in GET Request all the request parameters data will be provided in the address bar as a Query String, it is visible to every USer, so no security for the data.

POST request will provide more Security for the data, whereas in POST request, User provided request parameter data will not be displayed in the Browser’s address bar. So security will be provided to the data in POST requests.

  1.  GET Request will not implement encryption mechanisms over the data that we want to send to the network.

POST request will implement encryption over the data that we want to transfer in the Network.

  1. GET requests support Bookmarks.

POST request does not support Bookmarks.

  1. GET request supports only character data.

POST request supports Binary data.

  1. The main utilization of the GET request is to perform Download operations.

The main utilization of the POST request is to perform Upload operations.

GET vs HEAD

If we submit a GET request for a particular Server side resource then the Server software will identify the requested resource and the Server software will send the total requested resource as response to the client machine.

If we submit a HEAD request for a particular Server side resource then the Server software will identify the requested resource and the Server software will send only the resources Metadata as response to the client in the form of Response Formats Header part.

OPTIONS

The main purpose of this request type is to know the number of HTTP methods that are supported by the present Server.

PUT

It can be used to override[Update] the Server  side resources.

DELETE

It can be used to delete the resources from the Server side application.

TRACE

It can be used to trace the request path.

It can be used to get the working status of a particular Server side resource.

Status Codes

Status code is a number that represents the status of the current request processing. 

Http protocol has provided the following  Status codes.

1XX —–> 100 to 199 ——> Informational Status Codes.
2XX —–> 200 to 299 ——> Success related Status Codes.
3XX —–> 300 to 399 ——> Redirection Status Codes.
4XX —–> 400 to 499 ——> Client Side Error.
5XX —–> 500 to 599 ——> Server side Error.

In Web applications, when Server dispatch response to the client , Protocol will take the response, Protocol will create a Response Format with the Header part and BODY part, in Header part there is a field “Status Line Code”  to represent status code value which is provided by the Server software.

When Response Format reached to the CLient Machine, Client Browser will take status code value from the status line field from the Response Format header part , Browser will check the status code and Browser will take the decision of displaying response to the users or not, or redirecting request to some other web application or displaying error messages on the basis of the Status codes.


Server

Server is a software , it is able to receives the requests from clients and it is able to send responses to the Clients. 

The main roles of the Server in the web applications is,

  1. Get requests from the clients.
  2. Identify the requested resource in the web applications.
  3. Execute the requested resource at the server machine.
  4. Generating response to the respective client.

EX: Tomcat, Weblogic, Wildfly, Glassfish,….

All the Servers are divided into the following two groups.

Web Servers

Application Servers

Web server v/s Application server?

Web Servers are able to provide a very good environment to execute web applications.

EX: Up to Tomcat5.x version, tomcat Server is Web Server.

ApplicationServers are able to provide a very good environment to execute both web applications and Distributed applications. 

EX: Above Tomcat5.x version, Tomcat is Application Server.

EX: Weblogic, Wildfly, Glassfish

Server component v/s Container

When we install Server software in the Server machine , Server software will provide the following two components.

  1. Main Server
  2. Container

Q) What is the difference between Main Server and Container?

When we submit a request from Client to Server, at Server machine, Main Server will take the request and Main Server will perform the following activities.

  1. The Main Server will check whether the request is a good request or a bad request.
  2. If the request is a bad request then the Main Server will send the respective error response to the client.
  3. If the request is good then the Main Server will check whether the request is for static resource or dynamic resource.
  4. If the request is coming for a static resource then the Main Server will handle it by sending the requested resource as response to the client.
  5. If the request is coming for any Dynamic Resource like Servlet or JSP,… then the Main Server will forward the request to the Container, where the Container will perform the following actions.
    • Container will identify the requested resource name and its application from the request URI.
    • Container will execute the requested resource by following the resources lifecycle.
    • Container will generate a response and send it to the Main Server.
  1. If the response is received from the Container, Main Server will send the generated response to the client through the protocol.

Types of Containers

There are 3 types of Containers on the basis of the container’s physical existence.

  1. Standalone Container: It is an integration of Main Server and Container as a single component.
  2. In-Process Container: It is a container that exists inside the Main Server.
  3. Out-Of-Process Container: It is a container that exists outside of the Main Server.

On the basis of the Server side components technologies which we have used to prepare Server side components there are 3 types of containers.

  1. Servlet Container: It has the Servlet lifecycle implementation internally and it will execute only Servlet components.
  2. JSP Container: It has the JSP life cycle implementation internally and it executes JSP pages only.

Note: Both Servlet container and JSP Container are called Web Containers.

  1. EJB Container: It has the EJB’s lifecycle implementation internally and it executes the EJB components only.