WebSocket connection send with multiple parameters

35 views
Skip to first unread message

Carsten Cerny

unread,
Jan 3, 2016, 5:53:34 PM1/3/16
to nodejs
Hi,

in my HTML-Code I have 3 jquery sliders to change 3 different values.

I found an example to send one value to my server-app:

connection.send(ui.value);

My server-app receive the value with the following code:

connection.on('message', function(message) {

My question: How can I send 3 values from the 3 sliders with one send command? I was thinking about I can concat the 3 values with an comma as an limiter, but it doesn't work. Next try was to send an javascript array, but it also doesn't worked.

Can you help me with a tip? At the end of the day there is a Raspi with an RGB-LED-Stripe and node.js installed. Now I can switch on/off the stripe and change the brightness of one color (I can send only one value atm).

Regards,
Carsten

Christopher Mina

unread,
Jan 3, 2016, 10:55:29 PM1/3/16
to nodejs
You can write your array, or any other object, to a string using JSON.stringify(value), and send that. On the server, use JSON.parse(value) to reconstruct the object.

In this way, you can send highly structured information through a socket.

Best of luck
Chris
Reply all
Reply to author
Forward
0 new messages