I have 3 variables to send to the client using socket.io, namely, mapRes & location.
server.js
var mapRes = {width : 720, height: 1040};
var location = [{x:100,y:100,z:100},{x:200,y:200,z:200}];
var obj = {'1':{x:100,y:200}}, '2':{x:200,y:100}};
io.on("connection", function(socket){
socket.emit("mapRes",mapRes);
socket.emit("location",location);
socket.emit("object",obj);
}
client.html
socket.on('mapRes',function(message){
var mapRes = message;
console.log(mapRes);
});
socket.on('location',function(message){
var location = message;
console.log(location);
});
socket.on('object',function (message){
var object = message;
console.log (object);
});
At the client side (browser), the first variable mapRes is received as expected.
Object { width: 720, height: 1040 }
The second variable, however, is received as shown below:
Array [ Object, Object]
The third object is received as below:
Object { 1: Object, 2: Object}
Is there a way to receive these variables/objects properly?
