3

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

1 Answer 1

4

You should first convert your data to JSON: socket.send(JSON.stringify(val)). Then on Node's end, it is trivial to get your original array: var arr=JSON.parse(yourReceivedData);

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.