It this possible, or do you have to force another socket.io connection to the client when he enters another HTML file in the same web area?
2 Answers
i think 1 connection will do the job. Look at this code:
var io = require('socket.io')(server);
io.sockets.on('connection', function(socket) {
console.log("user connected");
socket.on('from_client', function(data) {
io.sockets.emit('to_client', data);
});
});
Above 'user connected' is printed when a new when a new browser tab opens localhost:8000 and thus, you can use the same socket.io for every open browser window(emit sends the msg to all the clients). Thus, as for what you asked, the answer is no, changing the html of an open/existing client doesnt require you to create a new socket/
1 Comment
user3262713
But when I try to access the socket variable I created in another HTML file it says that it is undefined.