浏览器内聊天如何工作? [英] How does in-browser chat work?

查看:77
本文介绍了浏览器内聊天如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

很好奇。在浏览器中聊天到底如何工作?通常,如果用户访问网页,则他/她的网络浏览器会请求页面内容。服务器产生输出,并将其发送到用户的计算机。但是,与聊天聊天的方式恰恰相反(并非完全如此)。不是用户从某个服务器请求聊天消息,而是直接发送该消息的服务器。现在,使用普通服务器确实很容易实现,但是服务器将其发送到浏览器的事情直接使我感到困惑。消息部分的发布很清楚,很简单。您只需使用诸如ajax之类的东西将数据发布到服务器。但是另一台计算机如何立即知道已写入消息?显然,它必须是服务器在将其写入后立即将其发送到另一台计算机。但是,这在我的大脑中是无法计算的。在我的大脑中,浏览器仅请求事物,而不仅仅是获得它们。您究竟是怎么做到的?

Just curious. How exactly does chatting in a browser work? Usually if a user goes to a web page, his/her webbrowser requests the page content. A server produces output and sends it to the user's computer. But with chatting it's a little bit the other way around (well not exactly). It's not the user requesting a chat message from some server, but rather the server that sends it directly. Now this is really simple to achieve with a "normal" server, but the thing that the server sends it to a browser directly confuses me. The posting the message part is all clear, it's simple. You just post the data to the server with for example ajax or something. But how does the other computer instantly "know" that a message has been written to it? It must obviously be the server sending it to the other computer as soon as it has been written. But somehow that doesn't compute in my brain. In my brain, the browser only request things, it doesn't just get them. How exactly do you do that?

例如,以gmail进行Google对话。这是如何运作的?

Take google talk in gmail for example. How does that work? How is it implemented?

推荐答案

有一些推送技术,例如 Comet ,但并未广泛实施。在大多数情况下,这是通过轮询来完成的,并使用AJAX进行很小的间隔并下载任何自上次下载消息以来可用的新消息。

There are some push technologies, such as Comet, but they're not widely implemented. Most of the time this is accomplished via polling at some small interval with AJAX and downloading any new messages that are available since the last downloaded message.

这篇关于浏览器内聊天如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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