仅在桌面上使用 socket.io 获取 xhr 轮询错误
Getting xhr poll error with socket.io on desktop only
我正在使用 socket.io 在网络上制作多人游戏,但只有我在桌面上遇到此错误(而不是在 phone 上)。
完整错误是
socket.min.io.js:6 GET http://my.public.ip:8080/socket.io/?EIO=4&transport=polling&t=Ndge5Hh net::ERR_CONNECTION_TIMED_OUT
我通过这样做发现了 xhr 轮询错误:
socket.on("connect_error", (err) => {
console.log(`connect_error due to ${err.message}`);
});
显示connect_error due to xhr poll error
我已正确完成所有端口转发。
奇怪的是我 运行 2 个服务器在同一个文件上(但添加了两个事件侦听器),其中一个服务器工作正常但另一个服务器没有,所以我认为同一个文件是问题所在所以我将它们合并到单独的文件中,但错误仍然出现。
这是两个服务器文件:
//Login.js THE ONE THAT WORKS
const httpServer = require("http").createServer();
const io = require("socket.io")(httpServer, {
cors: {
origin: "http://my.website",
methods: ["GET", "POST"]
}
});
const port = 8081;
io.on("connection", (client) => {
console.log(`${client.id} joined`)
});
httpServer.listen(port);
//Game.js THE ONE THAT DOSENT WORK
const httpServer = require("http").createServer();
const io = require("socket.io")(httpServer, {
cors: {
origin: "http://my.website",
methods: ["GET", "POST"]
}
});
io.on("connection", (client) => {
console.log('joined')
});
httpServer.listen(port);
Update(); //A Function Thought this might be useful
编辑:
我忘了添加客户端 javascript 所以这里是:
//Connecting to Game.js
const socket = io("http://same.ip.checked:8080");//Ive tried http / https / none they all dont work
socket.on("connect", () => {
console.log("connected");
})
//Connecting to Login.js (One that works)
const socket = io("same.ip.checked:8081");
socket.once("connect", () => {
})
我发现端口 0808
被我的服务器路由器用作默认网关,所以我更改了端口并且一切正常 (:
我正在使用 socket.io 在网络上制作多人游戏,但只有我在桌面上遇到此错误(而不是在 phone 上)。
完整错误是
socket.min.io.js:6 GET http://my.public.ip:8080/socket.io/?EIO=4&transport=polling&t=Ndge5Hh net::ERR_CONNECTION_TIMED_OUT
我通过这样做发现了 xhr 轮询错误:
socket.on("connect_error", (err) => {
console.log(`connect_error due to ${err.message}`);
});
显示connect_error due to xhr poll error
我已正确完成所有端口转发。
奇怪的是我 运行 2 个服务器在同一个文件上(但添加了两个事件侦听器),其中一个服务器工作正常但另一个服务器没有,所以我认为同一个文件是问题所在所以我将它们合并到单独的文件中,但错误仍然出现。
这是两个服务器文件:
//Login.js THE ONE THAT WORKS
const httpServer = require("http").createServer();
const io = require("socket.io")(httpServer, {
cors: {
origin: "http://my.website",
methods: ["GET", "POST"]
}
});
const port = 8081;
io.on("connection", (client) => {
console.log(`${client.id} joined`)
});
httpServer.listen(port);
//Game.js THE ONE THAT DOSENT WORK
const httpServer = require("http").createServer();
const io = require("socket.io")(httpServer, {
cors: {
origin: "http://my.website",
methods: ["GET", "POST"]
}
});
io.on("connection", (client) => {
console.log('joined')
});
httpServer.listen(port);
Update(); //A Function Thought this might be useful
编辑: 我忘了添加客户端 javascript 所以这里是:
//Connecting to Game.js
const socket = io("http://same.ip.checked:8080");//Ive tried http / https / none they all dont work
socket.on("connect", () => {
console.log("connected");
})
//Connecting to Login.js (One that works)
const socket = io("same.ip.checked:8081");
socket.once("connect", () => {
})
我发现端口 0808
被我的服务器路由器用作默认网关,所以我更改了端口并且一切正常 (: