Reputation: 6197
lets have a "complex" site, there are three modules: "links", "home", "chat". Links, home just a static-like page, no need long polling, it doesnt even start. But in case "chat" any time a new message may arrive from other users, and I want to immediatly show it, without refreshing the site.
So, in "chat" a long-polling was started, and it detects that a new chat message arrived, so poll-requests finishes and sends a "send the chatbox-div" message - so that site may refresh the DIV.
But lets imagine three users are watching this module right now. How to notice all of them to refresh the content?
EDIT: how I imagine: lets somewhere save a flag which indicates that the message arrived, and the long polling request is watching this flag. If it changes, get the message, and zero that flag - but then its possible some users (some requests) wont notice that
Upvotes: 0
Views: 359
Reputation: 7785
Senario :
One Server;
N Clients in the same Chanel
The server implements a Pool for one chanel;
Pool is configured as follow (it can be an array/class/...) :
ID(Integer/string)
=> A new record is inserted if a client made a connection and it will be identified by his ID
=> This record will be deleted, if the client do deconnection or exit from this chanel
MESSAGES(String) : New Messages must be concatenated to the old that are already stored on the pool
Each Time that a client send a new message to the server
1 - All MESSAGES of the pool will be updated by concatenation unread messages by the new one (except for the sender)
Each Time that the client make a request to the server (using Ajax Long Pooling)
1 - the server will deliver him the right MESSAGE basing on his ID
2 - Erase MESSAGE
With this implementation, client can receive an empty message, so on front-end you have to do the appropriate operation
Upvotes: 1