关于浏览器行为时的响应从服务器发送的质询 [英] Question regarding browser behavior when a response is sent from a server

查看:131
本文介绍了关于浏览器行为时的响应从服务器发送的质询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

情景:


  • 浏览器提交一个HTTP请求到服务器。

  • 的用户同时按下书签或上产生一个新的请求给服务器的页面上的其他链路。

  • 现在,服务器发回两个HTTP响应(或者浏览器从两台服务器获得响应)。

如何在浏览器决定哪些反应的实际处理?

How does the browser decide which of the responses to actually process?

我知道会发生什么 - 我试图理解为什么。解释这个任何参考或网站,也将是多少AP preciated。

I know what will happen - am trying to understand why. Any references or websites that explain this would also be much appreciated.

感谢您,

维韦克。

编辑:询问后看到这个类似问题。请合并/删除,如果合适的。

Saw this similar question after asking. Please merge/delete if appropriate.

推荐答案

有关的网络编程是怎么做的一般讨论,请参阅的这个问题

For a general discussion of how network programming is done, see this question.

简短的回答您的具体问题是,接收(在浏览器中),服务器的响应是接收浏览器的请求(服务器内)的不同。当浏览器打开到服务器的新连接,它在做什么是创建一个套接字,然后调用连接发送在该插座。当服务器收到这个传入连接,它可能并不关心这是否是相同的客户端的一些previous连接。如果不小心(例如已登录的会议或购物车),它使用Cookie或诸如此类的东西,如果用previous那些此连接相关联。 (我忽略持久连接,这超出你的问题的范围。)

The short answer to your specific question is that receiving a server's response (within a browser) is different from receiving a browser's request (within a server). When the browser opens a new connection to the server, what it's doing is creating a socket and then calling connect and send on that socket. When the server gets this incoming connection, it might not care if this is the same client as some previous connection. If does care (e.g. it has logged-in sessions or shopping carts) it has to use cookies or whatnot if to associate this connection with previous ones. (I'm ignoring persistent connections, which are beyond the scope of your question.)

但是,当浏览器接收来自服务器的响应,它通过调用的recv ,它用来发送请求的同一个插座上这样做,所以它知道哪个请求该响应去与它甚至开始读它。从理论上讲,浏览器维护它所打开的连接状态信息。在实践中,它具有一个列表或插座阵列

But when the browser receives the response from the server, it does so by calling recv on the same socket that it used to send the request, so it knows which request that response goes with before it even starts reading it. In theoretical terms, the browser is maintaining state information about the connections it has open. In practical terms, it has a list or array of sockets.

该浏览器还跟踪哪个窗口和标签都与socket相关联。这是它如何更新纺织和状态线以反映相应的连接状态。如果用户点击停止按钮,它知道应该停止哪些插座(或插座)。

The browser also keeps track of which windows and tabs are associated with which sockets. This is how it can update the spinners and status lines to reflect the status of the corresponding connections. And if the user clicks the stop button, it knows which socket (or sockets) to close.

因此​​,在你的场景中,用户点击与再presenting到服务器的响应没有接收服务器的连接到现有的套接字相关的窗口或选项卡链接或书签。该浏览器可以简单地关闭套接字,如果用户点击了停止按钮。而且,即使它没有关闭它,浏览器知道用户不再希望看到的响应。同时它会打开一个新的socket向用户感兴趣的服务器。

So in your scenario, the user has clicked a link or bookmark in a window or tab associated with an existing socket representing a connection to a server where the server's response hasn't been received yet. The browser can simply close that socket as if the user had clicked the stop button. And even if it didn't close it, the browser knows the user no longer wants to see the response. Meanwhile it opens a new socket to the server the user is interested in.

这篇关于关于浏览器行为时的响应从服务器发送的质询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆