简体   繁体   English

如何获得实时更新?

[英]How to get realtime updates?

I was chatting frequently in Facebook and as I love to code more and more so I tried to create a Chat Script: Here it is::: http://wooflux.co.cc/ChatSystem.1.1/ChatSystem.1.1/我经常在 Facebook 聊天,因为我越来越喜欢编码,所以我尝试创建一个聊天脚本:这里是::: http://wooflux.co.cc/ChatSystem.1.1/ChatSystem.1.1/

You try it out.你试试看。 But it is just a beta version so there are some bugs in it.但它只是一个测试版,所以它有一些错误。 And one of the biggest bug is that it requires a good internet speed to get real time updates.最大的错误之一是它需要良好的互联网速度才能获得实时更新。 But when I push my net's speed to it's maximum and then chat with one of my friends in Facebook, it work in real time?但是当我把我的网速推到最大,然后和我在 Facebook 的朋友聊天时,它是实时工作的吗? I was wondering how did they do that.我想知道他们是怎么做到的。 Can anyone explain me how they achieved this.谁能解释一下他们是如何做到这一点的。 Currently I'm sending Ajax requests in number intervals to get real time update?目前我正在以数字间隔发送 Ajax 请求以获得实时更新? So please help me out by explaining or giving a link that how did Facebook achieved real time Chats without using much of the Internet speed?因此,请通过解释或提供链接来帮助我,说明 Facebook 如何在不使用太多 Internet 速度的情况下实现实时聊天?

To do real time communication you need a proper connection.要进行实时通信,您需要正确的连接。

You can use WebSockets to give you a real Browser - Server TCP connection.您可以使用WebSockets给您一个真正的浏览器 - 服务器 TCP 连接。

The alternative to WebSockets would be a flash bridge (which uses websockets in flash) or COMET techniques. WebSockets 的替代方案是 flash 桥接器(在闪存中使用 websockets)或COMET技术。

My personal recommendation is a WebSocket abstraction like socket.io .我个人的建议是 WebSocket 抽象,如socket.io

Socket.io builds on node.js which Serverside Javascript. Socket.io 建立在服务器端 Javascript的 node.js 之上。 It excels at evented asynchronous real time communication.它擅长事件异步实时通信。

If your going down the node route you might aswell pick up now to make your life easy.如果你沿着节点路线走,你最好now就开始,让你的生活更轻松。 It has a screencast about making a chat server in 12 lines.它有一个关于在 12 行中制作聊天服务器的截屏视频。

I don't know how Facebook does it, but we use Node.js for pushing.我不知道 Facebook 是怎么做到的,但是我们使用Node.js进行推送。 Visit http://www.no-margin-for-errors.com/blog/2010/07/26/deliver-real-time-information-to-your-users-using-node-js/ for an example.有关示例,请访问http://www.no-margin-for-errors.com/blog/2010/07/26/deliver-real-time-information-to-your-users-using-node-js/

Use COMET to push your messages to the client instead of polling your server all the time使用COMET将您的消息推送到客户端,而不是一直轮询您的服务器

See: Using comet with PHP?请参阅:将彗星与 PHP 一起使用?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM