问题描述
所以我有这个建立socket.io连接的应用程序。它显示一个游戏(chrome恐龙游戏),当一个游戏失败时,客户端发出请求,并触发服务器端的traceroute脚本,从第三方服务器获取IP位置,然后将位置传递给客户端,其中映射到了一个 Leaflet.js 地图上。
代码在我的本地机器上完美运行,但是一旦我将它上传到heroku,它就会显示以下错误:
index.js:83 GET https://floating-dusk-44098.herokuapp.com/socket.io/?EIO=3&transport=polling&t=NZclCXa 503(服务不可用)
我的服务器端代码:
const express = require("express");
const bodyParser = require("body-parser");
const fetch = require('node-fetch');
//Node Traceroute
const traceroute = require('nodejs-traceroute');
const app = express();
//socket import
const httpServer = require("http").createServer(app);
const options = {
/* ... */ };
const io = require("socket.io")(httpServer,options);
//Establishes the socket connection
io.on("connection",socket => {
console.log("Connection established");
//Gets some IP addresses and a list with locations,as well as a list with the name of those locations
const randomId = Math.floor(Math.random() * IPlist.length)
var item = IPlist[randomId];
var chIpLoc = IpLocations[randomId];
var locName = ipLocationName[randomId];
socket.emit("videoID",randomId);
//Listens for Game Over socket event
socket.on("gameOver",function(data){
console.log(data);
//Traceroute Code
let IPinfo = require("node-ipinfo");
try {
const tracer = new traceroute();
tracer
.on('pid',(pid) => {
console.log(`pid: ${pid}`);
})
.on('destination',(destination) => {
console.log(`destination: ${destination}`);
socket.emit("firewallData",{
destLocation : chIpLoc,destName : locName,});
})
.on('hop',(hop) => {
if (hop.ip == 'Request timed out.') {
console.log('No IP found for this hop');
} else {
console.log(hop.ip);
// Ip lookup code
let token = tokens[Math.floor(Math.random() * tokens.length)];
let ip = hop.ip
let ipinfo = new IPinfo(token);
ipinfo.lookupIp(ip).then((response) => {
console.log(response.loc);
socket.emit("serversLocation",response.loc);
});
}
})
.on('close',(code) => {
console.log(`close: code ${code}`);
});
tracer.trace(item);
} catch (ex) {
console.log(ex);
}
客户端代码:
<script src="/socket.io/socket.io.js"></script>
<script>
const socket = io();
socket.on("serversLocation",(arg) => {
console.log(arg);
mapServerLocation(arg);
});
socket.on("videoID",(id) => {
console.log(id);
vidFile = id;
});
socket.on("firewallData",(fire) => {
console.log("Firewall Data: ",JSON.stringify(fire));
mapDestination(fire.destLocation[0])
document.getElementById("destText").textContent = "Destination: " + fire.destName;
});
</script>
非常感谢任何帮助!
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)