dimanche 25 juin 2017

Are node.js clusters different instances entirely?

I have a simple websocket multiplayer game using socket.io.

I am using clusters right now and for each new worker I instantiate a new gameServer object and do gameServer.start();

GameServer.prototype.start = function () {  
    var express = require("express");
    var app = express();
    var server = require('http').Server(app);

    /** INIT PORT CONNECTION **/
    app.get('/', function (req, res) {
        res.sendFile(__dirname + '/web/index.html');
    });
    app.use('/', express.static(__dirname + '/web'));
    server.listen(2000); //port number for listening
    console.log('Started Server!');

Each gameServer object includes its own PLAYER_LIST, APPLE_LIST, etc.

Does that mean that each worker will have different data? Will that mean that if a user connects to one worker it might not have the complete data set and be on a completely DIFFERENT server?

Thanks.




Aucun commentaire:

Enregistrer un commentaire