Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I create a chat server that is not driven by polling?

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.

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).

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).

like image 390
Felixyz Avatar asked Jan 24 '23 09:01

Felixyz


2 Answers

How about push technology? see http://en.wikipedia.org/wiki/Comet_(programming)

like image 139
txwikinger Avatar answered Jan 29 '23 08:01

txwikinger


I think you're describing XMPP over BOSH.

http://xmpp.org/extensions/xep-0206.html

I've used this http-binding method between a chat server and javascript client on non-mobile devices. It worked well for me.

like image 25
ire_and_curses Avatar answered Jan 29 '23 07:01

ire_and_curses