node.js - New websocket on different instance of site -


i have remote control 4 devices running on node server.

each device has own page (/1, /2, /3, /4), generated same html/js.

the difference ip each device, loaded json on server depending on url path.

this works, problem is: have 3 wrong ips entered testing purposes, , 1 correct one. if open correct one, go parent page , open page of device wrong ip, still shown online , can controlled.

i understand like: socket stays open across pages , not built new on every site.

how can make sure each subpage generates new socket?

right now, have

socket = new io.connect(); 

in browser.js,

ioserver.on('connection', function (socket) {     //etc. } 

in app.js , works 1 device.

am right assume need kind of "destroy socket if page changed"-function?

thanks help

by looks of it, want instantiate , boot device when device's client connects first time , emits 'startup'. if not case, i'd instantiate , boot each device when server starts.

going first case, i'd store devices in key-value object , reuse them when needed.

var devices = {};  ioserver.on('connection', function (socket) {      var client_ip_address = socket.request.connection.remoteaddress;     console.log("new connection from: " + client_ip_address);      var device;      socket.on('startup', function (data) {          var deviceid = data.device;          console.log("[info] startup: device " + deviceid);          //if device in devices, resuse             if (deviceid in devices) {              //get device devices object             device = devices[deviceid];          //otherwise, create new device , store in devices         } else {              device = new hyperdeck(deviceid);              //store new device in devices object             devices[deviceid] = device;              device.boot();         }          console.log(device.id);         console.log(device.ip);     });      ... 

Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -