dimanche 29 mars 2015

New websocket on different instance of site

I have a remote control for 4 Devices running on a node server.


Each device has its own page (/1, /2, /3, /4), but they are all generated from the same html/js.


the only difference is the ip for each device, loaded from a json on the server depending on the url path.


This all works, but the problem is: i have 3 obviously wrong IPs entered for testing purposes, and one correct one. Now if i open the correct one, go back to the parent page and open the page of a device with a wrong IP, it is still shown as online and can be controlled.


I understand this like: the socket stays open across the pages and is actually not built new on every site.


how can i make sure that each subpage generates a new socket?


right now, i just have



socket = new io.connect();


in the browser.js,



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


in the app.js and it works for ONE device.


Am I right to assume that I need some kind of "destroy socket if page is changed"-function?


Thanks for the help


Aucun commentaire:

Enregistrer un commentaire