从 Redis for Windows https://github.com/tporadowski/redis/releases
安装后启动redis-server.exe
python manage.py shellimport channels.layers
channel_layer = channels.layers.get_channel_layer()
from asgiref.sync import async_to_sync
async_to_sync(channel_layer.send)('test_channel', {'type': 'hello'})
async_to_sync(channel_layer.receive)('test_channel')期望输出:
{'type': 'hello'}python manage.py runserver进入 http://127.0.0.1:8000/chat/ 输入聊天室名称进入聊天
双页面进入 http://127.0.0.1:8000/chat/lobby/ 发送消息可以看到两边都能收到消息