亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Lance-gg游戲socket.io無法在數字海洋上加載資源

Lance-gg游戲socket.io無法在數字海洋上加載資源

縹緲止盈 2023-09-21 16:40:06
我的 lance-gg 游戲可以在本地主機上運行,但現在我嘗試在數字海洋上部署,該網站似乎正在托管,但我無法連接 socket.io??蛻舳藶g覽器的錯誤是:[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 socketconst 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 Instancesconst 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 engineconst 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服務器?
查看完整描述

1 回答

?
慕田峪9158850

TA貢獻1794條經驗 獲得超7個贊

沒關系,解決了我在客戶端代碼中的問題。顯然,在云環境中,我不需要像在本地主機上那樣指定端口 3001。


// ...


import { USE_CLOUD_SERVER } from './constants';

const options = {

    // ...


    // The cloud server is set up with Nginx to redirect to the right port.

    serverURL: USE_CLOUD_SERVER ? 'http://144.126.196.39' : 'http://localhost:3001'

};


// ...


查看完整回答
反對 回復 2023-09-21
  • 1 回答
  • 0 關注
  • 112 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號