【发布时间】:2021-07-18 21:46:27
【问题描述】:
我已经检查了很多问题和教程,并且正在关注 socketme 门户网站的官方文档。我在 XAMPP/Localhost 上运行它。
当我不使用 WAMP 接口时,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 方法并使用以下普通方法:
$server = IoServer::factory(
new HttpServer(
new WsServer(
new WampServer(
new WebSocketHandler()
)
)
),
8080
);
但是,它没有用。
非常感谢任何帮助。
【问题讨论】:
-
最新的高速公路实现了 WAMP v2。我尝试使用 Thruway 路由器实现,但我对 onMessage、onOpen、onClose 等方法的控制为零,因此,我想继续使用 Ratchet WAMP v1。赏金是针对可以与 WAMP v1 后端通信的兼容库。
标签: php websocket ratchet autobahn