Getting started with flask sockets can be very hectic especially with very clumsy demos available in the internet. I struggled very much to find a very basic working version of it. I have posted here a simple example to let you understand the very basics of socket in flask application. I have added necessary comments to make things clearer here.
- Uses flask_socketio for serverside and socket.io.min.js for client side
I love to create virtual environment for each and every projects and supply requirements.txt file for them to keep my system fresh and clean.
# Create a virtual environment for this app
$ virtualenv projectenv
# Activate the app's virtual environment
$ source projectenv/bin/activate
$ cd simple-flask-socket
# Then install all dependencies using
# requirements.txt file included with the project
$ pip install -r requirements.txt
# Run the server
$ python app.py
Now you can visit the url http://127.0.0.1:5050/ Please try this out and let me know.