views:

719

answers:

1

I am doing Comet chat with Erlang. I only use one connection (long-polling) for the message transportation. But, as you know, the long-polling connection can not be stay connected all the time. Every time a new message comes or reaches the timeout, it will break and then connect to the server again. If a message is sent before the connection re-connected, it is a problem to keep the integrity of chat.

And also, if a user opens more than one window with Comet-chat, all the chat messages have to keep sync, which means a user can have lots of long-polling connections. So it is hard to keep every message delivered on time.

Should I build a message queue for every connection? Or what else better way to solve this?

+1  A: 

For me seems simplest way to have one process/message queue per user connected to chat (even have more than one chat window). Than keep track of timestamp of last message in chat window application and when reconnect ask for messages after this timestamp. Message queue process should keeps messages only for reasonable time span. In this scenario reconnecting is all up to client. In another scenario you can send some sort of hart beats from server but it seems less reliable for me. It is not solving issue with other reason of disconnection than timeout. There are many variant of server side queuing as one queue per client, per user, per chat room, per ...

Hynek -Pichi- Vychodil
Thanks for your answer. And this way is also what I am using now. Only one little problem: delayed messages can only be sent after next time the long-polling connection establishes(or with a new coming message) , so there will be a little latency.
Mickey Shine
You also can use heart beat messages to avoid disconnection but not rely on it for consistency.
Hynek -Pichi- Vychodil