开发者

How to implement a server side push so that the client doesn't miss any pushs froms the server?

开发者 https://www.devze.com 2023-02-04 09:12 出处:网络
I have to develop a real-time web application, where the server needs to inform all of its clients if something bad happened via an alarm message.

I have to develop a real-time web application, where the server needs to inform all of its clients if something bad happened via an alarm message.

It is crucial that the client must not miss any alarm, i.e. even if the client is down temporarily, it must receive any sent alarms if it is online again.

Any ideas how to implement such a mechanism? The number of clients is very small (5-10), so performance/bandwidth may not be an issue.

EDIT

Totally missed the point that the client has to receive the alarms in (nearly) realtime, so E-Mail may not be th开发者_Go百科e best solution.


Two possible approaches:

  1. Have the client confirm each received alert and keep track of each client's status on the server.
    • Slightly higher bandwidth requirements.
    • Dumb client/smart server.
    • Much more complex server.
    • Gives the server full control and supervision.
    • Good for "real push" (realtime binary stream kinda thing), if that's what you have in place.
  2. Timestamp or otherwise uniquely id each alert, have the client tell the server what the latest known timestamp was and have the server formulate an appropriate response to get the client up to date.
    • RESTful approach.
    • Dumb server/smart client.
    • Server doesn't necessarily know the status of each client.
    • Easy to re-sync after connection dropout.
    • Better suited for poll-type architecture.

The optimum is probably somewhere in between in a hybrid solution.


As far as I know you can't actually push to your web clients.

Assuming you have a list (on the server) of the clients then every time you have a message to send, record the fact it needs reading against each client in a database.
Write your client app with some JS to poll the server asking for unread messages. Show unread messages and then write back an acknowledgement.

For this you will need

  • a database containing all clients, all messages and a matrix of message status to clients (read/acknowledged).
  • Some kind of web service to a) get all unread messages for a given client and b) to acknowledge message(s) for a given client.
  • Ajax type stuff on the client side for the polling
  • Dynamically change the HTML to show any messages you get back.
  • Ajax type stuff to let the server know you've shown the message(s) and not to retrieve them again for that client.
0

精彩评论

暂无评论...
验证码 换一张
取 消