gpt4 book ai didi

php - Autobahn-js 无法连接到 Ratchet Server (Wamp)

转载 作者:行者123 更新时间:2023-12-04 16:13:09 25 4
gpt4 key购买 nike

我已经检查了很多问题和教程,我正在关注 socketme 门户的官方文档。我在 XAMPP/Localhost 上运行它。
当我不使用 WAMP 接口(interface)时,Websocket 可以工作。否则,它无法连接并且不说明任何原因。
错误是:“app.js:6200 WebSocket 连接到‘ws://localhost:8080/socket’失败:连接关闭无法访问”
服务器

$server = new \Ratchet\App('localhost', 8080);
$server->route('/socket', new WebSocketHandler, array('*'));
$server->run();
WebSocketHandler 是 WampServerInterface 的基本实现并且只包括抽象的方法,没有任何变化。
在客户端,我正在执行以下操作以尝试通过 autobahn-js 进行连接:
           var connection = new Autobahn.Connection({

transports: [{
type: 'websocket',
port: 8080,
host: 'localhost',
url: 'ws://localhost:8080/socket'
}],
realm: 'realm1'
});

connection.onopen = function(session) {
app.content = app.content + `connected!`
};

connection.onclose = function(reason, details) {
app.content = app.content + `onclose!`
}

connection.open();
我在这个实现中做错了,但我想不通。我试过避免 ->route方法并使用以下 Vanilla 方法:
$server = IoServer::factory(
new HttpServer(
new WsServer(
new WampServer(
new WebSocketHandler()
)
)
),
8080
);
但是,它没有用。
任何帮助深表感谢。

最佳答案

您需要 Autobahn.js 0.8.2 才能将其连接到 Ratchet (WAMP v1),这是一个非常古老的实现,而且 ab 0.8.2 也非常古老。
您应该将您的工作导航到 Thruway。我尝试这样做,但找不到 Thruway RatcherRouter 的任何自定义实现(onMessage、onOpen 等),因此,我决定自己(非常糟糕)实现 Ratchet。
TL; DR:切换到高速公路。

关于php - Autobahn-js 无法连接到 Ratchet Server (Wamp),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68433313/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com