I've been working on some type of game where I have to pass a map which is available as an Array to the players. I already looked at other posts who suggested to pass the array as an object but this produces the following problem: 1. The user doesn't receive the object or the array 2. I got a script that logs whenever a client (dis)connects and it's showing me that a client always connects and disconnects. (Probably the client times out and tries to reconnect??)
The server code looks like this:
io.sockets.on('connection', onConnect);
function onConnect(socket) {
console.log("We have a new client: " + socket.id);
socket.emit('field', {fields});
socket.on('disconnect', function() {
console.log("Client " + socket.id + " has disconnected!");
});
}
And the client code:
socket = io.connect('http://localhost:3000');
socket.on("field",
function(data) {
console.log(data);
}
);
I'm able to pass a single object of the array, but not the whole one...
Edit: The code itself works with a string but not with an array that I want to be passed...