Node.js and the Socket.io array obtained in pieces

I have a problem sending an array using socket.io. The client creates an array, populates it, and sends it using socket.send (val), where val is the array. However, the server side, the socket does not receive the array as an array, it receives the individual parts of the array as separate messages, therefore the entire array is not available in client.on ('message', function (only one element of the array) {...}); Am I just an idiot doing something completely wrong? I do not '

+3
source share
1 answer

First you need to convert your data in the JSON: socket.send(JSON.stringify(val)). Then at the end of Node it is trivial to get the original array:var arr=JSON.parse(yourReceivedData);

+4
source

All Articles