我已经查看了大量的问题和教程,并且正在遵循socketme门户网站的官方文档。我正在XAMPP/本地主机上运行。
当我不使用WAMP接口时,Websocket可以正常工作。否则,它无法连接并且没有说明原因。
错误是:"app.js:6200 WebSocket connection to 'ws://localhost:8080/socket' failed: connection closed unreachable"
服务器
$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
);
但是,它没有起作用。
非常感谢任何帮助。