Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to send array using QWebSocket

How to send array using QWebSocket

Scheduled Pinned Locked Moved General and Desktop
websocketnode.js
4 Posts 3 Posters 3.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Athair
    wrote on 3 Apr 2015, 14:54 last edited by Athair 4 Mar 2015, 14:56
    #1

    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! :)

    1 Reply Last reply
    0
    • T Offline
      T Offline
      TobyYi
      wrote on 4 Apr 2015, 01:15 last edited by
      #2
      • 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

      将QtCoding进行到底,做Qt的宠儿
      关注移动互联网,关注手机助手
      开发即时通讯,服务于金融行业
      My github :https://github.com/toby20130333

      P 1 Reply Last reply 4 Apr 2015, 05:44
      0
      • T TobyYi
        4 Apr 2015, 01:15
        • 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
        P Offline
        P Offline
        p3c0
        Moderators
        wrote on 4 Apr 2015, 05:44 last edited by
        #3

        @TobyYi We would appreciate if you post some example codes/solution here instead of advertising your blog.

        157

        1 Reply Last reply
        0
        • A Offline
          A Offline
          Athair
          wrote on 8 Apr 2015, 08:06 last edited by
          #4

          Thank you for your advice! I have simplified: I converted the array into a single string

          1 Reply Last reply
          0

          4/4

          8 Apr 2015, 08:06

          • Login

          • Login or register to search.
          4 out of 4
          • First post
            4/4
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved