django-mease
============
Work in progress
Websocket integration made easy for Django using Tornado, Redis PUB/SUB and easy to use callback registry mechanism.
## Installation
### Dependencies (Debian & Ubuntu)
```
sudo apt-get install redis-server python-dev
```
### Install django-mease
```
pip install django-mease
```
### Add mease to your INSTALLED_APPS
```python
INSTALLED_APPS = (
...
'mease',
)
```
## Usage
### Start websocket server
`python manage.py start_websocket_server`
### Register callbacks
Create `mease_registry.py` files to register your callbacks (the file must be located in an installed app):
```python
import mease
def receive_websocket_message(client, message, clients_list):
for c in clients_list:
c.write_message(message)
mease.receiver(receive_websocket_message)
def send_websocket_message(channel, message, clients_list):
for c in clients_list:
c.write_message(message)
mease.sender(send_websocket_message, channels=['websocket'])
```
Receiver functions are called when a message is sent from the client.
`mease.receiver` functions must take 3 parameters:
1. the client (tornado WebSocketHandler instance)
2. the message content
3. a list of all connected clients (list of tornado WebSocketHandler instances)
---
Sender functions are called when a message is sent from the server.
`mease.sender` functions must take 3 parameters:
1. a list of all connected clients (list of tornado WebSocketHandler instances)
2. the target channel
3. the message content
A sender function can be registered for a list of channels, otherwise it is registered for all channels.
### Publish
Use `mease.publish` to publish from anywhere in your code :
```python
import mease
mease.publish('websocket', "Hello world !")
```
This will call all sender functions registered on the 'websocket' channel.
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
资源分类:Python库 所属语言:Python 资源全名:django-mease-0.1.7.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
资源推荐
资源详情
资源评论
收起资源包目录
django-mease-0.1.7.tar.gz (26个子文件)
django-mease-0.1.7
MANIFEST.in 63B
PKG-INFO 3KB
mease
server.py 4KB
management
commands
__init__.py 0B
start_websocket_server.py 2KB
__init__.py 0B
decorators.py 848B
permissions.py 332B
__init__.py 167B
subscribers
redis.py 395B
__init__.py 0B
base.py 497B
settings.py 529B
publisher.py 542B
registry.py 1KB
tests.py 388B
exceptions.py 68B
LICENSE 1KB
setup.cfg 59B
setup.py 1KB
README.md 2KB
django_mease.egg-info
PKG-INFO 3KB
requires.txt 62B
SOURCES.txt 584B
top_level.txt 6B
dependency_links.txt 1B
共 26 条
- 1
资源评论
挣扎的蓝藻
- 粉丝: 14w+
- 资源: 15万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功