我只了解节点js。我正在为网络游戏制作服务器。已经在network.js(功能服务器)中监听代码。但在Heroku中它需要收听index.js或者应用程序会崩溃...我已经在google中搜索如何解决这个问题,但我没有得到它
请帮帮我:)。
index.js
var express = require('express');
var app = express();
app.set('port', (process.env.PORT || 5000));
app.use(express.static(__dirname + '/'));
app.listen(app.get('port'), function() {
console.log('Node app is running on port', app.get('port'));
});
var WORLD_SX = 128;
var WORLD_SY = 128;
var WORLD_SZ = 32;
var WORLD_GROUNDHEIGHT = 16;
var SECONDS_BETWEEN_SAVES = 60;
var ADMIN_IP = "127.0.0.1";
// Load modules
var modules = {};
modules.helpers = require( "./js/helpers.js" );
modules.blocks = require( "./js/blocks.js" );
modules.world = require( "./js/world.js" );
modules.network = require( "./js/network.js" );
modules.io = require( "socket.io" );
modules.fs = require( "fs" );
var log = require( "util" ).log;
// Set-up evil globals
global.Vector = modules.helpers.Vector;
global.BLOCK = modules.blocks.BLOCK;
// Create new empty world or load one from file
var world = new modules.world.World( WORLD_SX, WORLD_SY, WORLD_SZ );
network.js
...
function Server( socketio, slots )
{
var express = require('express');
var app = express();
var http = require('http').Server(app);
app.use(express.static('.'));
var io = this.io = socketio(http);
var s = this;
io.sockets.on( "connection", function( socket ) { s.onConnection( socket ); } );
this.eventHandlers = {};
this.activeNicknames = {};
this.activeAddresses = {};
this.maxSlots = slots;
this.usedSlots = 0;
this.oneUserPerIp = true;
http.listen(5000, function() {});
}
答案 0 :(得分:1)
您必须在文件index.js或文件network.js中更改端口5000。在同一个端口上监听两个应用程序是不可能的。