WebSocket is a communication protocol for the client-server model.

So for understanding WebSocket, It is batter to compare the WebSocket specialty over HTTPS.

There are a few advantages of WebSocket over HTTPS that is what the specialty of WebSocket.

So If we have to decide that we should choose the WebSocket for our applications then we can analyze the requirements as per the below-written features of WebSocket.

HTTP carries extra overheard in individual request and response, WebSocket carries the overhead data while placing connection then it carries less or balanced data within individual request-response.

Image for post

Difference HTTP vs WebSocket

Note: For full-duplex Bi-directional client-server communication the WebSocket is the best choice.

The WebSocket’s can be implemented with all server-side technologies, I am using Flask and Socket-IO modules from Python.

Please understand the steps below to implement the WebSocket using Flask and Socket-IO


Step1: Creating a project and creating requirements.txt

  • First of all, will start by setting up the virtual environment for our sample project.
  1. Create a project folder.
  2. Create a requirments.txt file into the project folder.
  3. Add below code into requirments.txt.
Flask==1.0.2
Flask-Login==0.4.1
Flask-Session==0.3.1
Flask_SocketIO
itsdangerous==1.1.0
Jinja2==2.10
MarkupSafe==1.1.0
python-engineio
python-socketio
six==1.11.0
Werkzeug==0.14.1

Note: the above dependency is required for implementing a web socket so we will install all for creating the virtual environment.

#sockets #websocket #flask-socketio #socketio #flash-website-design

Implement a WebSocket Using Flask and Socket-IO(Python)
2.15 GEEK