Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Forum Updated on Feb 6th

    How to send array using QWebSocket

    General and Desktop
    websocket node.js
    3
    4
    2872
    Loading More Posts
    • 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
      Athair last edited by Athair

      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 Reply Quote 0
      • TobyYi
        TobyYi 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

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

        p3c0 1 Reply Last reply Reply Quote 0
        • p3c0
          p3c0 Moderators @TobyYi last edited by

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

          157

          1 Reply Last reply Reply Quote 0
          • A
            Athair last edited by

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

            1 Reply Last reply Reply Quote 0
            • First post
              Last post