[英]Deploying node.js + socket.io backend/server on azure
在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手机上播放,我使用统一游戏引擎制作了游戏。
当我在本地运行服务器时,它运行完美! 多个实例连接到服务器并加入会议室,ai正在播放,乐谱正在更新等。但是我不能让它在服务器端进行通信/运行。
希望以下内容能有所帮助。
1)在Azure Web Apps中,只有端口80和443是面向公众的。 因此,您的连接字符串应类似于:
ws://MyAppname.azurewebsites.net/socket.io/?EIO=4&transport=websocket
2)Socket.IO使用WebSocket,默认情况下未在Azure上启用。 要启用Web套接字,请按照我之前的文章中的步骤进行操作。
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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.