

debug=True enables to sort out the errors with ease. The run() method takes optional host and port arguments, but by default it will listen on localhost:5000 like Flask’s development web server. socketio encapsulates startup of the web server, i.e. SocketIO is being applied to ‘app’ and is later being stored in socketio variable which enables us to use socketio instead of app in running the application. To enable encryption, we’re declaring a SECRET_KEY. Now, create a variable named app by wrapping Flask around _name_. To import SocketIO class from flask_socketio module, all we need to do is: from flask_socketio import SocketIO PIP enables us to install this ‘flask-socketio’ extension, to do so, run the command: $ pip install flask-socketio In our case, we shall be using a javascript library which is Socket.JS. The client-side application can use any of the SocketIO official client libraries in Javascript, C++, Java and Swift, or any compatible client to establish a permanent connection to the server.


Flask-SocketIO gives flask applications access to bi-directional communications between the clients and the server. There’s an extension known as ‘flask-socketio’ which enables us to do. How do we get to create a socket in Flask? Using SocketIO, you can be pretty much sure that any browser out there will be able to connect to your application. SocketIO is a cross-browser Javascript library that abstracts the client application from the actual transport protocol. Since chat is all about communication, sockets are essential. In simple terms, it could be considered as a gate which enables the communication only if the gates are open, i.e only if the socket’s open. It establishes a path through which one computer can interact with the other. Let’s get a basic understanding of what a socket is. from flask import Flask About and Installing SocketIO Let’s create a file named main.py and import Flask class from the flask module, the below snippet explains how to do it. Jump to the required directory where you’re writing the source code and type: $ pip install flask Just go to the terminal in case it’s Mac OS or Linux and command prompt if it’s Windows.
