var socket = io(); /*Initializing the connection with the server via websockets */ socket.emit('liveMessage', "true"); socket.on("jsonHoneycomb",function(message){ /* When server sends data to the client it will trigger "message" event on the client side , by using socket.on("message") , one cna listen for the ,message event and associate a callback to be executed . The Callback function gets the dat sent from the server */ console.log("Message from the server arrived") var honeyCells = JSON.parse(message); if( honeyCells.constructor === Array){ for (var i = 0; i < honeyCells.length; i++) { populateHoneycomb( honeyCells[i], i ); }; }else{ populateHoneycomb( honeyCells , 0); } socket.emit('ackMessage', "true"); });