我正在尝试使用 websockets 主要用于将数据从服务器推送到客户端的事件。
所以,我在本地配置了Thruway和Autobahn.js两次:我自己和本教程的帮助。
服务器正确启动:
./bin/console thruway:router:start
Making a go at starting the Thruway Router
2018-05-23T00:29:33.6760270 debug [Thruway\Peer\Router 17047] New router created
2018-05-23T00:29:33.6830490 info [Thruway\Peer\Router 17047] Starting router
2018-05-23T00:29:33.6853010 info [Thruway\Transport\RatchetTransportProvider 17047] Websocket listening on 127.0.0.1:9998
2018-05-23T00:29:33.6864550 info [Thruway\Transport\RatchetTransportProvider 17047] Websocket listening on 127.0.0.1:9999
2018-05-23T00:29:33.6865040 info [Thruway\Peer\Router 17047] Starting loop
浏览器代码很简单:
var connection = new autobahn.Connection({
url: 'ws://127.0.0.1:9999/',
realm: 'realm1'
});
connection.onopen = function (session, details) {
console.info('Connection opened: ' + session + ' | ' + details);
};
connection.onclose = function (reason, details) {
console.info('Connection closed: ' + reason + ' | ' + details);
};
connection.open();
426 No Sec-WebSocket-Protocols requested supported
但我在浏览器(Safari、Chrome、FireFox)中看到错误。
经过一番谷歌搜索,我发现只有非常古老的问题/答案(2014..2016),人们说 Authobahn.js 使用 WAMPv2,但 Ratchet 仅使用 WAMPv1.. 但我看到 Thruway 库在 2017-2018 年支持 WAMPv2。
我的问题很简单:如何做到这一点?或者,也许,使用 angularWAMP?任何例子表示赞赏,谢谢。
版本:
~ composer show -D
sensio/distribution-bundle v5.0.21 Base bundle for Symfony Distributions
sensio/framework-extra-bundle v5.1.6 This bundle provides a way to configure your controllers with annotations
sensio/generator-bundle v3.1.7 This bundle generates code for you
symfony/monolog-bundle v3.2.0 Symfony MonologBundle
symfony/phpunit-bridge v4.0.9 Symfony PHPUnit Bridge
symfony/polyfill-apcu v1.8.0 Symfony polyfill backporting apcu_* functions to lower PHP versions
symfony/swiftmailer-bundle v3.2.2 Symfony SwiftmailerBundle
symfony/symfony v3.4.9 The Symfony PHP framework
thruway/pawl-transport 0.5.0 Pawl WebSocket Transport for Thruway Client
voryx/thruway-bundle 0.3.1 WebSockets (WAMP2) integration for Symfony2
高速公路是 18.3.2