带有http api的基于gevent的异步websocket服务器。

wsnotifier的Python项目详细描述


Build Status

wsnotifier是基于轻量级gevent的 用python编写的异步websocket服务器。wsnotifier公开http 用于将消息转发到WebSocket客户端的API。就这样 更易于将该服务与任何web应用程序一起使用。完全是 用python编写,不依赖于redis之类的外部系统 存储/检索消息。

wsnotifier components

安装

您可以使用pip

安装
$ pip install git+https://github.com/semk/wsnotifier.git

或使用Docker

$ docker pull semk/wsnotifier

运行wsnotifier服务器

$ wsnotifier
Starting wsnotifier on ws://0.0.0.0:1729/alerts and http://0.0.0.0:1729/alerts

或使用Docker

$ docker run -p 1729:1729 --rm -it semk/wsnotifier
Starting wsnotifier on ws://0.0.0.0:1729/alerts and http://0.0.0.0:1729/alerts

通过WebSocket客户端连接到wsNotifier

wscat是一个不错的命令行websocket客户端。您可以通过

$ npm install -g wscat

连接到位于ws://0.0.0.0:1729/alerts

的WebSocket服务器
$ wscat -c ws://localhost:1729/alerts
connected (press CTRL+C to quit)

向wsnotifier发送消息以转发到websocket客户端。

您可以使用任何http客户端发送消息。这将被转发 异步连接到所有连接的WebSocket客户端。python客户端 for wsnotifier可用here

$ curl -X POST -H "Content-Type: application/json" -d '{"id": "unique-message-id", "type": "important", "message": "important message"}' http://0.0.0.0:1729/alerts
{"status": "success"}

您可以在wscat客户端上看到转发的消息 立即。

$ wscat -c ws://localhost:1729/alerts
connected (press CTRL+C to quit)
< {"message": "important message", "type": "important", "id": "unique-message-id"}
>

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java IntelliJ找不到依赖项选项卡   java向字符串数组string[]添加元素并在Junit中测试结果   如何在eclipse中获取活动java项目的名称   如何使用java在mysql中插入时间   java ArrayList更新了插入一行,但Jtable仍然没有刷新   如何在JavaSwing中命名坐标(点)   java Matcher/模式不打印   java错误地设置了arraylist   使用UsernamePasswordCredential提供程序的java列表Azure AD   java在HTTP请求中设置UTC时间   未加载事件:jquery完整日历Java集成   java Maven插件依赖项无法从内部repo解析依赖项   Maven更新重置Java版本   java如何向中添加图片。带有Apache POI XWPF的docx,但不指定其大小   Java最大函数递归