What is the best way to update all clients when Flask database changes without polling?

梦想的初衷 提交于 2019-12-02 11:42:15

Yes you are correct. You need sockets. There are bunch of articles over the internet but I would like to give a summary and try to explain why sockets will be the best fit to your requirements.

Sockets are way of achieving two way communication between client and server without the need of polling.

There is a package called Flask-SocketIO

Flask-SocketIO gives Flask applications access to low latency bi-directional communications between the clients and the server.

Then for the scenario where you would like to send changes to all the connected client when one client does some work to your database or something similar, you will need to use broadcasting. When a message is sent with the broadcast option enabled, all clients connected to the namespace receive it, including the sender. Here you can find details of the broadcasting using Flask-SocketIO.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!