The simplest way is to use ajax to continuously access the backend interface to see if there is any news. Hupu seems to be like this. The second method is to use socketio to maintain the connection between the client and the server so that they can communicate at any time. It's not clear how socketio is implemented. It doesn't matter whether you use websocket or Socket, you just need to know that it can maintain the connection. Basically these are the two methods. . .
If the number of messages is not large, you can consider using long polling. HTTP connections have more resources than web sockets and can maintain more connections. But flask’s long polling may need to use threads? Otherwise, an http connection will block the entire web app. Link is recommended to use Tornado, which comes with ioloop, official chat room example
socketIO
https://github.com/miguelgrinberg/Flask-SocketIO
There are examples inside
The simplest way is to use ajax to continuously access the backend interface to see if there is any news. Hupu seems to be like this. The second method is to use socketio to maintain the connection between the client and the server so that they can communicate at any time. It's not clear how socketio is implemented. It doesn't matter whether you use websocket or Socket, you just need to know that it can maintain the connection. Basically these are the two methods. . .
If the number of messages is not large, you can consider using long polling. HTTP connections have more resources than web sockets and can maintain more connections.
But flask’s long polling may need to use threads? Otherwise, an http connection will block the entire web app. Link
is recommended to use Tornado, which comes with ioloop, official chat room example