我正在构建一个应用程序,可以在其中查看日志中的实时更改 该应用程序是使用Symfony v4.1构建的。有this捆绑包,其中包含基于Ratchet和Autobahn.js的Web Socket服务器和客户端
我已经根据文档设置了所有要求,以使其能够正常工作。
有一个Topic类:
pubsub路由已配置
服务器正在运行
加载页面时客户端在javascript中运行
在我订阅频道/主题之前,连接脚本可以正常工作。连接立即在客户端关闭,而服务器未检测到该连接。有谁知道如何解决这个问题?另外,我很好奇此响应码WS-1007的含义。
Javascript:
var ws = WS.connect("ws://" + $websocket_host + ":" + $websocket_port);
ws.on("socket/connect", function(session) {
if (window.$debug) {
console.log("websocket connected");
}
console.log(session);
session.subscribe("log/channel", function(uri, payload) {
console.log(payload);
});
});
ws.on("socket/disconnect", function(e) {
if (window.$debug) {
console.log("websocket disconnected [reason:" + e.reason + " code:" + e.code + "]");
}
});
JavaScript日志:
~ websocket connected
~ websocket disconnected [reason:Connection was closed properly [WS-1007: ] code:0]
服务器日志:
14:15:39 DEBUG [websocket] INSERT CLIENT 2926 ["user" => "s:37:"anon-19491835335b991f8bde43b229754494";"] []
14:15:39 INFO [websocket] anon-19491835335b991f8bde43b229754494 connected ["connection_id" => 2926,"session_id" => "19491835335b991f8bde43b229754494","storage_id" => 2926] []
14:15:39 DEBUG [websocket] GET CLIENT 2926 [] []
14:15:39 INFO [websocket] anon-19491835335b991f8bde43b229754494 subscribe to log/channel [] []
14:15:39 DEBUG [websocket] Matched route "shop4_log" [] []
14:15:39 DEBUG [websocket] Matched route "shop4_log" [] []
主题类别:
namespace App\Service\WebSocket\Topic;
use Gos\Bundle\WebSocketBundle\Router\WampRequest;
use Gos\Bundle\WebSocketBundle\Topic\TopicInterface;
use Ratchet\ConnectionInterface;
use Ratchet\Wamp\Topic;
class LogTopic implements TopicInterface
{
public function onPublish(ConnectionInterface $connection, Topic $topic, WampRequest $request, $event, array $exclude, array $eligible)
{
$topic->broadcast(['msg' => $event]);
}
public function getName()
{
return "log_topic";
}
....
}
pubsub.yaml
shop4_log:
channel: log/channel
handler:
callback: "log_topic"