I haven't found a good described example for that. Ones I found are either too old and use old versions of used libraries (which is not ideal) or don't work because of a version compatibility issue(s). I managed to make it work, but it did take a few hours.
I hope this example will help someone to not waste the same amount of time.
It's a python web server that serves an HTML page with a chat-like interface. You can send messages, which are processed by flask-soketio and broadcasted to everyone connected to the main page.
The example is hosted on heroku, you can visit it and try it out for yourself here. Open up two tabs with it and chat!
- All requirements are marked as exact versions, so version compatibility shouldn't become a problem
- I'm still working on an app with flask-socketio, this repo will be updated from time to time (last update date == last commit date)
- If some links go dead, I'll replace them, you can report such links in issues
CORS policy. Currently it's allowing any origins, that should never be a thing in a production environment. See flask-socketio
documentation for info on CORS configuration
- Clone the repo
- Create a virtual python environment (https://docs.python.org/3/library/venv.html)
- Open a console & activate the virtual environment
- Install requirements:
pip install -r requirements.txt
- Run the main file:
python main.py
- Done! Web server should be running at
http://localhost:5000/
- Clone the repo
- Open a console in repo's folder
- Create an application on heroku
- Login to heroku CLI:
heroku login
- Attach your heroku app as a git remote:
heroku git:remote -a your-app-name-here
- Push it to heroku:
git push heroku master
- Wait for it to deploy, when visit your applications page, and you're done!
-
Why an older version of eventlet is used:
-
Deployment of flask-socketio applications:
-
Client configuration: