> For the complete documentation index, see [llms.txt](https://learn.jwc.in.th/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://learn.jwc.in.th/programming-major/intermediate-website-development/client-server-architecture.md).

# Client Server Architecture

Generated by ChatGPT. Double check the correctness.

Client-server architecture is a network design model that divides networked systems into two main roles: clients and servers. Here's how it works:

**Components**

1. **Client**:
   * **Definition**: A client is a device or application that requests services or resources from a server. Examples include web browsers, mobile apps, and desktop applications.
   * **Function**: Clients send requests to servers for data or functionality. For example, when you enter a URL in your browser, it sends an HTTP request to the server hosting that website.
2. **Server**:
   * **Definition**: A server is a powerful computer or program that provides services or resources to clients. Examples include web servers, database servers, and application servers.
   * **Function**: Servers receive requests from clients, process them, and send back the appropriate response. For instance, a web server processes an HTTP request by retrieving the requested web page and sending it back to the browser.

**Interaction**

* **Request-Response Model**: The client-server interaction typically follows a request-response model. The client sends a request to the server, and the server processes this request and sends back a response.

#### How Client-Server Architecture is Related to HTTP

HTTP (HyperText Transfer Protocol) is a protocol that facilitates communication between clients and servers in the client-server architecture. Here’s how they are related:

**Communication Protocol**

* **Medium**: HTTP is the protocol used for the communication between the client (e.g., a web browser) and the server (e.g., a web server).
* **Request-Response Cycle**: HTTP defines how requests and responses are formatted, transmitted, and interpreted in the client-server model.

**HTTP Requests**

1. **Initiation**: The client initiates communication by sending an HTTP request to the server.
2. **Methods**: The request includes an HTTP method that indicates the desired action (e.g., GET, POST, PUT, DELETE).
3. **Headers**: The request may include headers that provide additional information about the request or the client.
4. **Body**: Some requests, such as POST, include a body with data to be processed by the server.

**HTTP Responses**

1. **Processing**: The server processes the received request and performs the necessary actions (e.g., retrieving data, updating records).
2. **Status Codes**: The server sends an HTTP response back to the client, which includes a status code indicating the result of the request (e.g., 200 OK, 404 Not Found).
3. **Headers**: The response may include headers that provide additional information about the response or the server.
4. **Body**: The response often includes a body with the requested data or an error message.

#### Example Workflow

1. **Client Request**:
   * A user enters a URL in a web browser (client).
   * The browser sends an HTTP GET request to the web server.
2. **Server Response**:
   * The web server receives the request.
   * The server processes the request, retrieves the requested web page, and sends an HTTP response with the content back to the browser.
3. **Client Rendering**:
   * The browser receives the HTTP response.
   * The browser processes the response (e.g., rendering HTML) and displays the web page to the user.

In summary, HTTP is the protocol that enables communication in the client-server architecture, allowing clients to request resources and services from servers and receive appropriate responses. This interaction is fundamental to the functioning of the web and many other networked applications.

{% embed url="<https://www.youtube.com/watch?v=B8azMzrluHE>" %}
