Flask-Soket IO Introduction

Flask-Soket IO Introduction

Flask is a Python web framework or module which allows the developer to create web applications with ease. The socket.io library is used to add some real-time functionality to the application. The socket.io library can be defined as a transport protocol that provides a real-time event-based communication which are bidirectional.

For this flask-socket.io module, the system will need: Python 2.7 or greater, Flask 0.9, SocketIO 0.8. It can be installed on all platforms, mac, or windows. Mac users can also use Homebrew as a package manager.


For installation write the command given below on command line(cmd) or the terminal:

pip install flask-socketio


pip3 install flask-socketio

if the system is having pip version 3.

In python language the following code represents how to import the flask-socket.io package for further use:

from flask import Flask
from flask import render_template
from flask_socketio import SocketIO

The code snippet given below shows the initialization of the package to be used:

application = Flask(__name__)
application.config[‘SECRET_KEY’] = ‘secret!’
socketio = SocketIO(application)
if __name__ == ‘__main__’:

The init_app() method can also be used for the initialization.

By executing the above python script the web server for socket.io will initiate.

The flask-socket.io module can be used for the following tasks:

·      Receiving Messages

·      Sending Messages

·      Broadcasting

·      Creating Rooms

·      Connection Events

·      Class-Based Namespace

·      Error Handling

·      Debugging and Troubleshooting