D
D
devchild2014-01-30 09:45:52
Web servers
devchild, 2014-01-30 09:45:52

How is the interaction between the web server (site) and the client?

Greetings.
I am new to web technologies, so I have a few questions that I would like to clear up. I broke one big question into several questions. In some questions, I assume that "it" works like this, and if I'm wrong, please correct me.
So, I'm interested in the interaction of a web server (for example, which hosts a site) and a client (which opens this site in its browser) at the transport level. Imagine that this site is built on AJAX technology. That is, the content is loaded dynamically. How the loaded content is rendered on the client using JS does not interest me. I can not understand the transportation of packages.
Questions:
1) What does synchronicity / asynchrony mean in web technologies?
2) The client opens the site in his browser. What's happening? Is a TCP/IP connection created? How does the server know where to send the packet when there is new content (AJAX)? Does it save information (doesn't it close?) TCP/IP connection and uses this transport to communicate with the client?
If so, then
3) Does this connection remain active until the client closes the tab with this site in his browser? And if the client opened a tab with the site and left for N hours to drink tea, then in this case the server should serve this connection for all these N hours? How resource intensive is this? If a client has opened N tabs with N sites in his browser, does that mean there are N TCP/IP connections open? What are the limits on the number of such connections for the client and for the server?
4) What technologies are used for chats?
I will be grateful for the answers.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
nekipelov, 2014-01-30
@devchild

1) What does synchronicity / asynchrony mean in web technologies?

That also means that works synchronous or asynchronously. A more extended answer depends on the context (did you mean the implementation of the http server, or the implementation of the interface, or maybe something else).
For example, opens the site www.ru/dir/page.html:
1. The browser must determine the ip address corresponding to the www.ru domain,
2. Establish a connection with the ip address on the default port 80.
3. Generate and send an HTTP request (GET /dir /page.html).
4. Get a response and process it.
If the request is initiated from JavaScript, the response is passed to it. If the browser itself, a page opens, if the response type is html, a picture, if the response type is a picture, or a javascript code is executed ....
In classic http, the server itself does not send anything to the client, it only responds to a request from its side. The client itself polls the server from time to time for new data. Whether the connection is closed or not depends on the protocol used (HTTP 1.1 supports the connection by default) and server/client settings (there are timeouts after which the connection is closed).
There are newfangled technologies, such as WebSockets. All steps are almost the same as for HTTP, but several virtual connections are multiplexed within one tcp connection. In this case, the WebSockets server can itself initiate the sending of data to the client (as well as the client to the server within the same tcp connection). Only the server will not know anything, its business is to send bytes. Initiates a server-side web application to send.
There are tricky techniques, such as opening an infinitely long page in a separate frame. The application on the server side does not report the final long page and the browser downloads it until it gets bored. In this case, the http server simply adds data to the rendered page as needed. However, client-server interaction will not work here, as in the case of WebSockets.
It all depends on how the applications are made from the server side and from the client side. In general, for chat, in the case of WebSockets, only one connection is established, which is not closed. In the case of HTTP, one supported with an infinite page (although it needs to be reopened from time to time) and by connection for each request from the client (whether a new connection will be opened here or work will continue within the framework of an already established one, it is better to ask fortunetellers, they have more experience in such cases).
Best suited are WebSockets and infinite frames. At the same time, WebSockets can be used both in the native implementation for the browser, and with the help of a flash plugin, in the absence of native support. Although no one bothers to do this with the help of a poll (long polling).
Probably the easiest way is to use something like socket.io, and it will figure out and decide on its own how to interact with the server.
PS: Of course, this is far from complete information, the topic is too serious.

P
pomeo, 2014-01-30
@pomeo

ajax is one way, i.e. we can send what we need from the client to the server. websockets to both, here we can already send from the server to the client.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question