我在PHP中使用带有此Ratchet库的websockets。它在我的本地机器上运行良好(没有流浪者)。
$loop = React\EventLoop\Factory::create();
$realtimeApp = new Ratchet\App('localhost', 2282, '0.0.0.0', $loop);
$loop->run();
var conn = new WebSocket('ws://localhost:2282');
conn.onopen = function (e) {
console.log("Connection established!");
};
conn.onerror = function (e) {
console.log("Connection error!");
};
conn.onclose = function (e) {
console.log("Connection closed!");
console.log(e);
};
但是,当我在我的虚拟机中使用它(使用vagrant)时,它不起作用。
$loop = React\EventLoop\Factory::create();
$realtimeApp = new Ratchet\App('192.168.56.101', 2282, '0.0.0.0', $loop);
$loop->run();
var conn = new WebSocket('ws://192.168.56.101:2282');
conn.onopen = function (e) {
console.log("Connection established!");
};
conn.onerror = function (e) {
console.log("Connection error!");
};
conn.onclose = function (e) {
console.log("Connection closed!");
console.log(e);
};
答案 0 :(得分:0)
我使用puphpet来生成木偶清单。问题是由防火墙引起的。默认情况下,puphpet会阻止除22(对于SSH)和80(对于apache和ngnix)之外的所有端口。我从puphpet GUI创建了防火墙规则并运行vagrant provision
并且它有效。