views:

247

answers:

2

I need to create a chat like facebook chat.

With Comet I need more memory to keep the connection.

With Ajax polling there is a latency problem if I send request every 3-4 seconds.

So... If the latency ( 3-4 seconds ) doesn't matter, Is Ajax Polling better for my case ?

+1  A: 

If latency isn't an issue then AJAX is probably better. Comet can encounter problems maintaining multiple connections between the same client/server pair if you're not very, very careful. (Ref)

Quotidian
+3  A: 

Latency is not the only problem. COMET (long-polling) "saves" your traffic - when you use polling, you cannot know, if there were changes on the server, so some of the calls may be just a waste of traffic and resources (e.g., even if no one's chatting, you're making calls every 3-4 seconds). In case of COMET, you generally need one just call to get an update from the server (with 100% hit rate).

Vasil Remeniuk
but with Comet, I need more memory to keep open the connections... no ?
xRobot
Keeping a connection itself is not so harmful. Memory consumption more depends on what server-side IO API you will chosee - blocking or non-blocking. If you choose the blocking API, you will have a thread per connection -> memory problems with 3-4k open connections. If you choose non-blocking API (almost every application server has NIO capabilities), you can keep millions of opened connection.
Vasil Remeniuk
You may find this interesting -- http://iobound.com/2008/11/comet-nio/
Vasil Remeniuk