Overv / WebCraft

Minecraft clone written in Javascript.
zlib License
386 stars 179 forks source link

listen in server.js #22

Closed ficopang closed 6 years ago

ficopang commented 6 years ago

can you make the listen in network.js to server.js, because in heroku need listen on main js(server.js) or crash. i dont know how to do it

Overv commented 6 years ago

You'll need to explain more about that requirement, because that doesn't make much sense.

ficopang commented 6 years ago

in heroku if deploy server.js, listen must be on server.js because heroku dont know the port(we cant change the port). so if server .js include listen on 5000, and network.js listen on 3000, it only show port 5000 and stop at connecting to server. so i want server.js is listen on 5000 and network.js too then i can run this webcraft on the online website :)

Overv commented 6 years ago

So you want me to add code that listens on some port in server.js, but doesn't do anything with it?

ficopang commented 6 years ago

Well i want in port 5000, and network.js doesnt need 'listen' on function server. So when i run server.js i can connect from port 5000. I already try experiment on the code but it still dont work

Overv commented 6 years ago

But why does it matter if the main file listens on a port or some other file that is included by the main file?

ficopang commented 6 years ago

In heroku, if no listen on deployed js(server.js), it will not work because heroku dont know what port to show in the website. And i want the 'listen' not in function Server so heroku can read it :D

Overv commented 6 years ago

I guess you could modify this function to look like this:

function Server( slots )
{
    this.eventHandlers = {};
    this.activeNicknames = {};
    this.activeAddresses = {};

    this.maxSlots = slots;
    this.usedSlots = 0;

    this.oneUserPerIp = true;
}

And modify the server creation code to look like this:

// Start server
var server = new modules.network.Server( modules.io, 16 );

var express = require('express');
var app = express();
var http = require('http').Server(app);
app.use(express.static('.'));

server.io = modules.io(http);
server.io.sockets.on( "connection", function( socket ) { server.onConnection( socket ); } );

http.listen(3000, function() {});
ficopang commented 6 years ago

Ill try it tomorrow, thanks!

ficopang commented 6 years ago

i already try it, it cant... but when i edit server.js little bit to: var port = process.env.PORT || 5000; http.listen(port, function() { console.log("Listening on Port 5000"); });

it fully work, thank you for help me :) you can check my webcraft on https://ficopangz.herokuapp.com/ i will update it. and again... THANK YOU!!