带有http api的基于gevent的异步websocket服务器。
wsnotifier的Python项目详细描述
wsnotifier是基于轻量级gevent的 用python编写的异步websocket服务器。wsnotifier公开http 用于将消息转发到WebSocket客户端的API。就这样 更易于将该服务与任何web应用程序一起使用。完全是 用python编写,不依赖于redis之类的外部系统 存储/检索消息。
安装
您可以使用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"} >