我的 lance-gg 游戏可以在本地主机上运行,但现在我尝试在数字海洋上部署,该网站似乎正在托管,但我无法连接 socket.io。客户端浏览器的错误是:
[Error] Failed to load resource: The request timed out. (socket.io, line 0) http://144.126.196.39:3001/socket.io/?EIO=3&transport=polling&t=NOU8Lc-
服务器代码是:
import path from 'path';
import express from 'express';
import socketIO from 'socket.io';
import { Lib, ServerEngine, GameEngine } from 'lance-gg';
// define routes and socket
const server = express();
server.get('/', (req, res) => { res.sendFile(path.join(__dirname, '../dist/index.html')); });
server.use('/', express.static(path.join(__dirname, '../dist/')));
let requestHandler = server.listen(3001);
const io = socketIO(requestHandler);
// Game Instances
const gameEngine = new GameEngine({ traceLevel: Lib.Trace.TRACE_NONE });
const serverEngine = new ServerEngine(io, gameEngine, { debug: {}, updateRate: 12 });
serverEngine.start();
客户端代码是:
import { Renderer, GameEngine, ClientEngine } from 'lance-gg';
const options = {
delayInputCount: 3,
scheduler: 'render-schedule',
syncOptions: {
sync: 'extrapolate',
remoteObjBending: 0.8,
bendingIncrements: 12
},
serverURL: 'http://144.126.196.39:3001'
};
// create a client engine and a game engine
const gameEngine = new GameEngine(options);
const clientEngine = new ClientEngine(gameEngine, options, Renderer);
document.addEventListener('DOMContentLoaded', (e) => clientEngine.start());
我了解 digital ocean 中的 nodeJS 入门模板使用 Nginx,因此我确保使用端口 3001 重定向到我的应用程序。
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/moon-game-2;
index index.html index.htm index.nginx-debian.html;
server_name hellonode;
location ^~ /assets/ {
gzip_static on;
expires 12h;
add_header Cache-Control public;
}
我怎样才能让我的socket.io也连接到我的lance-gg服务器?
慕田峪9158850
相关分类