浏览器内聊天如何工作?

发布于 2024-07-30 03:19:18 字数 424 浏览 4 评论 0原文

只是好奇。 在浏览器中聊天到底是如何进行的? 通常,如果用户访问网页,他/她的网络浏览器会请求页面内容。 服务器产生输出并将其发送到用户的计算机。 但对于聊天来说,情况就有点相反了(也不完全是这样)。 不是用户向某个服务器请求聊天消息,而是服务器直接发送消息。 现在,使用“普通”服务器实现这一点确实很简单,但是服务器将其发送到浏览器的事情直接让我感到困惑。 发布消息部分很清楚,很简单。 您只需使用 ajax 等将数据发布到服务器即可。 但是另一台计算机如何立即“知道”一条消息已写入其中呢? 显然一定是服务器在写入后立即将其发送到另一台计算机。 但不知怎的,这并没有在我的大脑中计算。 在我的大脑中,浏览器只请求东西,而不仅仅是获取它们。 你到底是怎么做到的?

以 Gmail 中的 google talk 为例。 这是如何运作的? 它是如何实施的?

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?

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

梦在深巷 2024-08-06 03:19:18

有一些推送技术,例如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.

浮华 2024-08-06 03:19:18

看看 Comet

Take a look at Comet

触ぅ动初心 2024-08-06 03:19:18

Orbited 是实现这一点的好方法,它使用彗星方法。 您可以找到教程 此处

有人提到了ajax轮询,但是 comet 总是比投票。 好吧,这只是一个耸人听闻的标题,但 Comet 绝对更合适,并且可以通过正确的后端减少服务器端的压力。

Orbited is a good way to implement this, it uses comet methodologies. You can find a tutorial here.

Someone mentioned ajax polling, but comet is always better than polling. Well, that's just a sensationalist title, but comet is definitely more appropriate and can lead to less stress on the server side, with the right back-end.

很快妥协 2024-08-06 03:19:18

它使用 AJAX - 在 GMail 用户浏览器上运行的客户端 JavaScript 发送并从 Google 服务器接收消息,并将它们写入浏览器窗口 - 无需重新加载页面。

It uses AJAX - a client-side javascript running on the GMail user's browser sends and receives the messages from the Google server, and writes them to the browser window - no reload of the page required.

不及他 2024-08-06 03:19:18

我开发了一种类似于 facebook 聊天技术的浏览器聊天 ( http://chatsign.com )。 它不是推送技术,而是比轮询更好的技术,它称为ajax长轮询。

有关 ajax 长轮询的更多信息,您可以进行一些研究或访问:http://techoctave.com/c7/posts/60-simple-long-polling-example-with-javascript-and-jquery

I've develop a browser chat similar to facebook chat technology ( http://chatsign.com ). It is not a push technology but something better than polling, its call ajax long polling.

For more information about ajax long polling you can do some research or visit : http://techoctave.com/c7/posts/60-simple-long-polling-example-with-javascript-and-jquery

爱你不解释 2024-08-06 03:19:18

现代聊天应用程序使用 SSE(服务器发送事件:html5 的一项功能)向浏览器发送新消息

Modern chat applications use SSE's (Server Sent Events: a feature of html5) to send new messages to browsers

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文