I've written a small web application which is basically a JQuery powered chat client within the browser, to get the posts I'm polling the server with an AJAX request and then appending any new replies, I'm worried about making this as efficient as possible while not losing the realtime feel.
http://darklightweb.co.uk/RealTime/
I can't see any way that interrupts are possible so I am polling a page every 5 seconds that returns nothing if no new posts are available to keep data-transfer down if it's idle, if it does have a message the top message in the queue is sent out and I'm checking again as soon as the Ajax request has finished until the message queue is empty.
Any other tips on making this as low-bandwidth as possible or possible alternate implementations?
Polling might not be the best solution for implementing a chat - I'd suggest taking a look at JQuery's implementation of COMET which keeps an open connection to the client and pushes updates from the server 'down' and is also quite scalable.
I think for a chat application you can use
Reverse Ajax
Reverse Ajax refers to an Ajax design pattern that uses long-lived HTTP connections to enable low-latency communication between a web server and a browser. Basically it is a way of sending data from client to server and a mechanism for pushing server data back to the browser.1
This server–client communication takes one of two forms:
* Client polling, the client repetitively queries (polls) the
server and waits for an answer. * Server pushing, a connection between a server and client is kept open, the server sends data when available.
Reverse Ajax describes the implementation of either of these models, or a combination of both. The design pattern is also known as Ajax Push, Full Duplex Ajax and Streaming Ajax.
and
moo-comet
Request.Comet is a simple javascript class to create cross browser Comet(Reverse Ajax) applications easily. It provides realtime data transfers between client and server and can be used with any server-sided language.
I've written almost EXACTLY the same application to facilitate communication between friends at work when various employers use draconian web filtering.
I found that the the amount of data transfered for these polling requests is minimal and rarely approaches 1kb/s per logged on user, usually way less since you're only polling ever 5s.
Is bandwidth really an issue or are you prematurely optimizing?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With