How to send array using QWebSocket
-
wrote on 3 Apr 2015, 14:54 last edited by Athair 4 Mar 2015, 14:56
Hi everybody!
I created a client-server system comprising:- A node.js server (with module ws);
- A WebClient;
- A QtClient (using Qt5.4 and QWebSocket).
The QtClient sends and receives strings via the method * QWebSocket.sendTextMessage (QString s)*. How can I send an array of strings?
The WebClient send array using JSON:
# index.html (WebClient) socket.onopen = function() { var array = { value1: "WebClient value1 = v1", value2: "WebClient value2 = v2" }; socket.send(JSON.stringify(array), {binary: true, mask: false}); }; # server.js socket.on('connection', function(ws) { ws.on('message', function(message) { var array = JSON.parse(message); console.log(array["value1"]); console.log( array["value2"]); }); }); # console node C:\Users\PietroP\Desktop\cs\v0.3>node server.js Server connect on http://192.168.1.60:3000/ a user connected WebClient value1 : v1 WebClient value2 : v2
Thanks for your support! :)
-
wrote on 4 Apr 2015, 01:15 last edited by
- You can also send array using JSON,for Details.You can look up The QWebsocket Class
- I develop a cross-platform app by Qt/QML,I also use websocket in my client.and my server use nodejs and websocket, this is my site :www.heilqt.com
-
- You can also send array using JSON,for Details.You can look up The QWebsocket Class
- I develop a cross-platform app by Qt/QML,I also use websocket in my client.and my server use nodejs and websocket, this is my site :www.heilqt.com
@TobyYi We would appreciate if you post some example codes/solution here instead of advertising your blog.
-
wrote on 8 Apr 2015, 08:06 last edited by
Thank you for your advice! I have simplified: I converted the array into a single string
4/4