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
Forum Updated to NodeBB v4.3 + New Features

How to send array using QWebSocket

Scheduled Pinned Locked Moved General and Desktop
websocketnode.js
4 Posts 3 Posters 3.2k Views 2 Watching
  • 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 last edited by Athair
    #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
    • TobyYiT Offline
      TobyYiT Offline
      TobyYi
      wrote on 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

      p3c0P 1 Reply Last reply
      0
      • TobyYiT TobyYi
        • 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
        p3c0P Offline
        p3c0P Offline
        p3c0
        Moderators
        wrote on 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 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

          • Login

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