Client-Server Architecture

 Client-Server Architecture: This is the most common web architecture. In this architecture, the client sends requests to the server, and the server processes those requests and sends back responses. The client is usually a web browser, and the server is a web server that can handle HTTP requests. Here is a simple example of client-server architecture using Node.js:

javascript


// server.js

const http = require('http');


const server = http.createServer((req, res) => {

  res.statusCode = 200;

  res.setHeader('Content-Type', 'text/plain');

  res.end('Hello World!');

});


server.listen(3000, () => {

  console.log('Server running at http://localhost:3000/');

});

In this code, we create a server using the createServer method of the http module. We handle incoming requests using the request event and send a response with the end method. The server listens on port 3000 for incoming requests.


php


// client.html

<!DOCTYPE html>

<html>

<head>

  <title>Client</title>

</head>

<body>

  <h1>Hello World!</h1>

</body>

</html>

In this code, we create a simple HTML file that displays the message "Hello World!" in the browser.

No comments:

Post a Comment

The Importance of Cybersecurity in the Digital Age

 The Importance of Cybersecurity in the Digital Age Introduction: In today's digital age, where technology is deeply intertwined with ev...