使用Flask和Socket-IO(Python)实现WebSocket

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.

W ebSocket是用于客户端-服务器模型的通信协议,因此为了理解WebSocket,比较HTTPS上的WebSocket专业知识是一个连击.WebSocket相对于HTTPS的一些优点正是WebSocket的特长。决定我们应该为我们的应用程序选择WebSocket,然后我们可以根据下面编写的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.

HTTP在单独的请求和响应中进行了额外的监听,WebSocket在放置连接时传递了开销数据,然后在单独的请求-响应内传递了较少或平衡的数据。

Image for post
Difference HTTP vs WebSocket
区别HTTP vs WebSocket

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

注意:对于全双工双向客户端-服务器通信,WebSocket是最佳选择。

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

WebSocket可以使用所有服务器端技术来实现,我正在使用Python的Flask和Socket-IO模块。请理解下面的步骤以使用Flask和Socket-IO来实现WebSocket

步骤1:创建一个项目并创建Requirements.txt (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.

    在项目文件夹中创建一个requirments.txt文件。
  3. Add below code into requirments.txt.

    将以下代码添加到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.

注意:以上依赖性是实现Web套接字所必需的,因此我们将安装所有这些组件以创建虚拟环境。

第二步:创建一个虚拟环境并从python安装所有必需的模块。 (Step2: Creating a virtual environment and install all required modules from python.)

  • Now create a virtual environment “VENV” for the project.

    现在为项目创建一个虚拟环境“ VENV”。
Image for post
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值