How client-server connection works on WEB

The client-server binomial is a constant concept in web programming, the relationship between back-end and front-end development is a whole, and although it is a relatively basic concept when understood, for the layman in the world of programming and especially the one on the web can be complex and somewhat confusing.

Content

  • How does the client-server work?
  • Who is the client in the web flow?
  • Who is the server in the web stream?
  • How do the client and server communicate?
  • Step-by-step client-server data flow

How does the client-server work?

We can refer to this relationship of “comradeship” between the two parts of web development: the communication between a client and a server. So that we understand each other, there is a client agent that makes requests for content (websites in our case) and a server agent that, apart from storing the web files, can “read” or “interpret” them.

The function of the client is to display content for reading, interpreting the files and information that it has requested from a server and that it has sent to it.

The function of the server is to attend or listen (technical concept) to requests/requests from clients, which at any given time can be one or many simultaneously.

Who is the client in the web flow?

The client is the web browser that you have installed and with which you view this page while reading my content. Your browser has the ability to interpret several programming languages ​​specially created for the display and layout of content.

Thanks to the languages ​​that it can interpret, the browser is capable of, for example:

  • Build buttons from an HTML tag.
  • Change the design of a part of a part of the web just by passing the mouse over it.
  • Show a different color in links to pages that you have already visited stored in your memory (cache).
  • Adapt texts and graphic elements according to the size of your browser window with CSS.

Who is the server in the web stream?

The server is specialized software for such a function installed on a computer that is on all day. The server literally spends hours waiting to receive a contact/call/request through the internet.

The server, among its main functions has:

  • Host files of all kinds, from images to programming files or databases.
  • Interpret files with server-specific programming and build a file based on it
  • Send a response message of variable size, either error (code 404 for example) or ok (code 200), with the content indicated by the programming of a web administrator.

How do the client and server communicate?

When the server receives a request from a client (it can be anywhere in the world), it performs a series of actions normally programmed in a server programming language, and sends an http response with the response content and some message headers. communication, whether error or ok everything has gone well.

If for any reason the server were “down”, that is, turned off or out of service, the client would receive a response from the Internet service provider or from the company in charge of hosting that equipment. This is commonly known as a 404 code with the related message: The page does not exist or is no longer available.

Step-by-step client-server data flow

To end this entire tutorial, I am going to explain in order how the flow of information from the client to the server and back would take place. Let’s see the process step by step conceptually:

  1. The web user visits the link www.srcodigofuente.com.
  2. The user’s browser sends an http request to the ip that corresponds to that domain name. The rest is taken care of by the service provider.
  3. The server, if it is not down, responds to the user’s request.
  4. Since the user has visited the root url of my website, the Apache server performs the default action: search for the file index.php in my root directory of web files.
  5. Apache opens the file and if, for example, the file has a .php extension, it scans it in case it has to execute programming language code on the server side (If the file had an html extension, Apache (the server) would send it from the file directly since you would not have to read code).
  6. When exploring the file, if it encounters client-side programming languages, they will be ignored, that is, they will be skipped, leaving those lines as they are.
  7. Every time the server software encounters, for example, #php (tag that indicates the start of php programming) it begins to interpret the code it finds in the lines that follow it, all of them lines with server-side programming.
  8. The server executes the code phpit ignores any client-side language that is found, and as it moves to the end of the file, the php code, or any other server-side language, having been parsed, will disappear from the final document.
  9. When Apache reaches the end of the file it sends it to the client as an internet message with some headers http. Thus, the user’s browser that visited the link to my website will now see an HTML page with a language to be interpreted and will build a graphic document with the corresponding design.
  10. If the page has files connected to it, such as CSS style sheets, images, or programming language libraries on the client side, the browser will request the indicated files from the server.
  11. If the received document contains client-side programming such as javascript, this is when code can be executed on the occurrence of scheduled events related to events produced by user user actions. The events range from a simple click by the user, the writing of a letter or the end of a certain period of time.

All this final code displayed by your browser can be seen by right-clicking and clicking on view page source code.

Leave a Reply