简体   繁体   中英

flask websockets app without serving webpage

I have an existing Python flask app that uses blueprints for routing. The app doesn't serve webpages, it just provides REST API for the client. Now I'm trying to add WebSockets support to this flask app to push some notifications to the client (they should originate on the server, not respond to client requests). I found Flask-SocketIO library, but it says that:

"The application must serve a page to the client that loads the Socket.IO library and establishes a connection."

Is there a way to use WebSockets in a flask app without serving webpages?

You can use the Flask-Sockets library that can be installed with pip. Just follow the documentation and examples shown in this page https://github.com/heroku-python/flask-sockets . It is fairly easy to use and does not need to have a page served by flask. Though you still need a page for your client's browser to originate from somewhere.

If you only want to use WebSockets you can also use the WebSockets library: https://pypi.org/project/websockets/ . Also easy to use and not linked to flask.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM