gpt4 book ai didi

javascript - 在azure上部署node.js + socket.io后端/服务器

转载 作者:行者123 更新时间:2023-12-03 04:48:19 28 4
gpt4 key购买 nike

D:\home\LogFiles\Application\logging-errors.txt 中的 Web 服务上运行服务器时出现以下错误:

Mon Mar 13 2017 21:36:58 GMT+0000 (Coordinated Universal Time): Application has thrown an uncaught exception and is terminated:
TypeError: server.listeners is not a function
at Server.attach (D:\home\site\wwwroot\node_modules\socket.io\node_modules\engine.io\lib\server.js:424:26)
at Function.attach (D:\home\site\wwwroot\node_modules\socket.io\node_modules\engine.io\lib\engine.io.js:124:10)
at Server.listen.Server.attach (D:\home\site\wwwroot\node_modules\socket.io\lib\index.js:240:21)
at new Server (D:\home\site\wwwroot\node_modules\socket.io\lib\index.js:52:17)
at Server (D:\home\site\wwwroot\node_modules\socket.io\lib\index.js:40:41)
at Object.<anonymous> (D:\home\site\wwwroot\server.js:1:92)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)

这是我的服务器端代码(它的开头):

var io = require('socket.io')(process.env.PORT || 3000);
var AI = require('./AI');
var gamelogic = require('./gamelogic');
var shortid = require('shortid');
var mongoose = require('mongoose');
mongoose.Promise = require('bluebird');

io.on('connection', function(socket){
socket.emit("Testing");

在客户端(C#,带有socket.io模块):

socket.On ("Testing", Test);

public void Test(SocketIOEvent e)
{
Debug.Log ("Server is running and communicating");

}

这是我到服务器的连接字符串:

ws://MyAppname.azurewebsites.net:3000/socket.io/?EIO=4&transport=websocket

游戏将在android手机上玩,我用unity游戏引擎制作了游戏。

当我在本地运行服务器时,它运行得很好!多个实例连接到服务器并加入房间,ai正在播放,分数正在更新等。但我不能让它在服务器端通信/运行它。

最佳答案

希望以下内容对您有所帮助。

1) 在 Azure Web Apps 中,只有端口 80 和 443 是面向公众的。所以你的连接字符串应该类似于:

ws://MyAppname.azurewebsites.net/socket.io/?EIO=4&transport=websocket

2) Socket.IO 使用 WebSocket,Azure 上默认未启用 WebSocket。要启用网络套接字,请按照 my earlier post 中的步骤操作。 .

3) 替换行:var io = require('socket.io')(process.env.PORT || 3000);包含以下代码行。

var server = require('http').createServer((req, res) => res.end());
var io = require('socket.io')(server);
server.listen(process.env.PORT || 3000);

关于javascript - 在azure上部署node.js + socket.io后端/服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42774193/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com