Question

I'm developing a chat application and I've come across the following thought.. Should I use 'multiple' long polling requests to my server, each one handling different things. For example one checking for messages, one for 'is typing', one for managing the contacts list 'is online/offline' etc.. or would it be better to handle it all through one channel?

Was it helpful?

Solution

Polling is going to be your biggest bandwidth/resource hog, so keep it to a minimum; e.g. issue HEAD requests with appropiate date / if-modified-since headers to allow caching to work sensibly, with the server returning just headers containing the date and time of the last change to any of the properties you're interested in - or perhaps something even more minimal than that; and only issue a full GET if the returned headers imply there is new information.

OTHER TIPS

My opinion is that you’d be better off with one connection, and sending JSON messages back and forth, e.g.:

User joined:

{"user_add": "st3"}

User left:

{"user_left": "sneeu"}

Message received

{"message": "Good morning!", "from": "st3"}

And these could be sent together in an array, so that users could receive everything since their last response.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top