与twisted进行网络聊天
我已经进行了一次可以通过 Telnet 连接的聊天。 我的聊天目前是作为 Twisted TCP 服务器实现的。 如何将其转换为浏览器聊天?
我想我应该使用 Comet 服务器(例如 Orbited)来同时提供静态 HTML 和动态内容。 对于快速可靠的聊天来说,这样的彗星服务器是否必要?
I've made a chat that I can connect with Telnet to. My chat is currently implemented as a Twisted TCP Server. How do I transform it into a chat for the browser?
I suppose I should use a comet server (e.g. Orbited) to be able to serve static HTML and dynamic content simultaneously. Is such a comet server necessary for a fast and reliable chat?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Comet 是最好的选择,无需使用任何特殊的东西(例如 Flash,见下文)。 这是一项经过验证的技术,许多大型网站都在使用它,例如 Gmail 的聊天室和 Facebook 的聊天室。
您唯一的其他选择是轮询,但这有时会对服务器造成影响。 基本上,您必须权衡服务器负载与速度 - 如果您经常轮询,您会得到一个响应非常快的客户端,但您会给服务器带来很大的负载。 轮询太少,您可以保持负载较轻,但客户端只能每n秒接收一次消息,因此看起来很慢。
如果您决定进行民意调查,您始终可以创建一个“后退”系统。 例如,页面每 2 秒检查一次是否有聊天消息发送。 它执行此操作 5 次,如果没有任何结果,则会将延迟增加到 3 秒。 它执行了 5 次,然后什么都不做,就变成了 4 秒……等等。 当发送聊天消息时,它会恢复到最短的延迟。
另一个更好的选择是使用 Flex 或 Flash 客户端。 这样,您就可以只使用 TCP 套接字,该套接字仅在有数据时发送数据。 但前提是您确实希望在您的网站上安装 Flash 应用程序。
Comet is the best option without using anything special (like Flash, see below). It's a proven technology and is used by many big sites, like Gmail's chat and Facebook's chat.
The only other option you have is polling, but that can sometimes get a bit intense on the server. You basically have to weigh server load against speed - if you poll often, you get a very responsive client, but you put a lot of load on your server. Poll too little and you keep the load light but clients can only receive messages every n seconds so it can seem slow.
If you decide to poll, you could always create a "back off" system. For example, the page checks every 2 seconds to see if there are any chat messages sent. It does this 5 times and if there is nothing, it increases the delay to 3 seconds. It does this 5 times and after nothing it goes to 4 seconds..etc. When a chat message is sent it goes back down to the shortest delay.
Another option to consider that is even better is using a Flex or Flash client. This way, you can just use TCP sockets which only send data if there is any. But that's only if you really want a Flash app on your site.
是啊,就是! 检查www.meebo.com! 他们以彗星为基础平台!
Yeah it is! Check www.meebo.com ! They use comet as their basic platform!