2
我试图用Django频道与浏览器建立一个websocket连接。 WebSocket的无法连接服务器:用于WebSocket的使用Django频道的Websocket
[2017/01/23 23:51:50] HTTP GET/200 [0.03, 127.0.0.1:60445]
[2017/01/23 23:51:51] WebSocket HANDSHAKING /chat/ [127.0.0.1:60451]
[2017/01/23 23:51:56] WebSocket DISCONNECT /chat/ [127.0.0.1:60451]
的Javascript:
socket = new WebSocket("ws://" + window.location.host + "/chat/");
socket.onmessage = function (e) {
alert(e.data);
};
socket.onopen = function() {
socket.send("hello world");
};
// Call onopen directly if socket is already open
if (socket.readyState == WebSocket.OPEN) socket.onopen();
settings.py
CHANNEL_LAYERS = {
"default": {
"BACKEND": "asgiref.inmemory.ChannelLayer",
"ROUTING": "django_chat_server.routing.channel_routing",
}
}
Routing.py
channel_routing = {
# Wire up websocket channels to our consumers:
'websocket.connect': ws_add,
'websocket.receive': ws_message,
'websocket.disconnect': ws_disconnect,
}
在装载该页面,ws_add
启动但连接最终断开。任何领导如何调试这个问题,或者是什么问题。
我使用命令python manage.py runserver
运行服务器。
编辑: 降级到twisted
版本16.2.0。徒劳无功。