我正在尝试在以下路径中路由websocket。
matrix.routing -> ws_consumer.routing -> chat.routing.
/matrix ->
/matrix
/wsconsumer
/chat
matrix
是我的应用名称,其他两个(ws_consumer
,chat
)是应用。
这些文件中的配置如下
ws_consumer_regex = r'^/ws_consumer'
channel_routing = [
include('ws_consumer.routing', path=ws_consumer_regex),
]
chat_regex = r'^/chat'
notification_regex = r'^/notification'
channel_routing = [
include('chat.routing', path=chat_regex),
include('notification.routing', path=notification_regex),
]
group_chat_name_regex = r'^/(?P<group_name>[a-zA-Z0-9_]+)/$'
group_chat_routing = [
route('websocket.connect', consumers.group_chat_connect, path=group_chat_name_regex),
route('websocket.receive', consumers.group_chat_receive, path=group_chat_name_regex),
route('websocket.disconnect', consumers.group_chat_disconnect, path=group_chat_name_regex),
]
group_chat_global_regex = r'^/group'
channel_routing = [
include(group_chat_routing, path=group_chat_global_regex),
]
var socket = new WebSocket('ws://' + window.location.host + '/ws_consumer/chat/group/test/');
socket.onopen = function open() {...};
socket.onmessage = function (event) {...};
if (socket.readyState == WebSocket.OPEN) {
socket.onopen();
}
在这些配置下,服务器正在启动时没有任何问题。但是在控制台中我遇到了错误。
VM2306:35 WebSocket connection to 'ws://localhost:8000/ws_consumer/chat/group/test/' failed: Error during WebSocket handshake: Unexpected response code: 404
Not Found: /ws_consumer/chat/group/test/
[19/Mar/2017 23:42:39] "GET /ws_consumer/chat/group/test/ HTTP/1.1" 404 2202
我还尝试直接路由到matrix.routing.py
中的消费者,这会让我遇到同样的错误。
from chat.consumers import group_chat_connect #consumer method
channel_routing = [
route('websocket.connect', group_chat_connect)
]
我在这里做错了什么?
答案 0 :(得分:0)
我发现该问题不包括对设置的INSTALLED_APPS的“频道”。