如何创建不受轮询驱动的聊天服务器? [英] How do I create a chat server that is not driven by polling?

查看:80
本文介绍了如何创建不受轮询驱动的聊天服务器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个由客户端轮询驱动的简单聊天服务器.客户端每隔几秒钟发送一次数据请求,并收到任何新消息以及有关其对等方是否仍处于连接状态的信息.

I have created a simple chat server that is driven by client polling. Clients send requests for data every few seconds, and get handed any new messages as well as information about whether their peer is still connected.

由于客户端在移动平台(iPhone)上运行,因此我一直在寻找摆脱轮询的方法,该方法会很快耗尽电池电量.我读过可以无限期地保持http连接打开,但还不了解如何在实践中利用此技术.我也想知道这样的连接是否足够稳定,可以在移动环境中使用.

Since the client is running on a mobile platform (iPhone), I've been looking for ways of getting rid of the polling, which quickly drains the battery. I've read that it's possible to keep an http connection open indefinitely, but haven't understood how to utilize this technique in practice. I'm also wondering whether such connections are stable enough to use in a mobile setting.

理想的情况是服务器仅在发生影响客户端的事件(例如,对等方发布消息或离线)时才将数据发送给客户端.

The ideal scenario would be that the server only sends data to clients when an event that affects them has occurred (such as a peer posting a message or going off line).

是否建议尝试通过http完成此操作,还是我必须通过tcp编写自己的协议?根据我的需要自定义xmpp会有多困难(我的聊天服务器具有一些必须轻松实现的特殊功能).

Is it advisable to try to accomplish this over http, or would I have to write my own protocol over tcp? How hard would it be to customize xmpp to my need (my chat server has some specialized features that I would have to easily implement).

推荐答案

推送技术如何?参见 http://en.wikipedia.org/wiki/Comet_(programming)

这篇关于如何创建不受轮询驱动的聊天服务器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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