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 can i send real time data(integer,string) from echoclient websocket in Qt to server?? as there is always defined constant string "Hello, world" being sent to the server on connection.
Forum Updated to NodeBB v4.3 + New Features

How can i send real time data(integer,string) from echoclient websocket in Qt to server?? as there is always defined constant string "Hello, world" being sent to the server on connection.

Scheduled Pinned Locked Moved Solved General and Desktop
11 Posts 3 Posters 3.5k Views 1 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.
  • R Offline
    R Offline
    Rahul Sharma
    wrote on last edited by
    #1

    Qt Echoclient Websocket Connetion done but No data sending.

    siropS 1 Reply Last reply
    0
    • R Rahul Sharma

      Qt Echoclient Websocket Connetion done but No data sending.

      siropS Offline
      siropS Offline
      sirop
      wrote on last edited by
      #2

      @Rahul-Sharma
      Which frequency of datagramm exchange do you plan?

      To be, or not to be: that is the question:
      Whether ’tis nobler in the mind to suffer
      The slings and arrows of outrageous fortune,
      Or to take arms against a sea of troubles,
      And by opposing end them?

      1 Reply Last reply
      0
      • R Offline
        R Offline
        Rahul Sharma
        wrote on last edited by
        #3

        I didn't get you properly. I just want to display data on server whenever it will be sent from client. I have a simple echoclient example from qtwebsocket page, and i connected that with a server written in java. connections are done and also shows connected. I am also able to send string message (start, stop) and is displayed to my echoclient consol. Problem is that in sending the data from echoclient is not happening. Only constant string is displaying in server as connection establish
        but i want to send data real time.

        1 Reply Last reply
        0
        • R Offline
          R Offline
          Rahul Sharma
          wrote on last edited by
          #4

          e.g the function is as "m_webSocket.sendTextMessage(QStringLiteral("Hello, World"));"
          so i just putted a simple count of 1 to 10 and put inside this. But it is not sending the count having errors.

          siropS 1 Reply Last reply
          0
          • R Rahul Sharma

            e.g the function is as "m_webSocket.sendTextMessage(QStringLiteral("Hello, World"));"
            so i just putted a simple count of 1 to 10 and put inside this. But it is not sending the count having errors.

            siropS Offline
            siropS Offline
            sirop
            wrote on last edited by sirop
            #5

            @Rahul-Sharma said:

            real time

            You should be careful with the term "real time": on real time OS hard real time could mean smth. like 200 us periodic task with a 20 us jitter. QtWebsocket would not work on that time scale. Even libwebsocket - the leanest websocket lib out there - will not do on that time scale.

            So if you mean "real time" as in Real Time OS, have a look zeroMQ , it is leaner and faster.

            If "real time" just means " as soon as possible", than show the errors of the Echoclient, please.

            To be, or not to be: that is the question:
            Whether ’tis nobler in the mind to suffer
            The slings and arrows of outrageous fortune,
            Or to take arms against a sea of troubles,
            And by opposing end them?

            1 Reply Last reply
            0
            • R Offline
              R Offline
              Rahul Sharma
              wrote on last edited by
              #6

              i solved it by firstly converting my integer value into string and the putting in the send method.

              And thanks for your support and information about the "real time".

              1 Reply Last reply
              0
              • R Offline
                R Offline
                Rahul Sharma
                wrote on last edited by
                #7

                I have another issue with that . As string data is sending to server so i send integer value (1 to 10). And it is printing in client console one by one but if i look into server then after ending upto 10, then only it displays all counting suddenly(not displaying one by one). So is there something i m not sending the data to server correctly?

                syntax is as follow -

                void EchoClient::onConnected()
                {

                   //m_webSocket.sendTextMessage("Hello sever");
                
                if (!m_debug)
                
                    qDebug() << "WebSocket connected";
                connect(&m_webSocket, &QWebSocket::textMessageReceived,
                        this, &EchoClient::onTextMessageReceived);
                
                for(int i=0; i<10;i++)
                 {
                    QString s = QString::number(i);
                // QString data = Dialog::robotDataSendQueue.enqueue(QString("bot1|"+s+"|0"));
                // data = Dialog::robotDataSendQueue.dequeue();
                // qDebug() << "queu data" << data;
                // m_webSocket.sendTextMessage(data);
                    qDebug()<< "s"<<s<<endl;
                    m_webSocket.sendTextMessage("bot1|"+s+"|0");
                   delay(500);
                }
                
                m_webSocket.sendTextMessage("bot1|10|0");
                delay(100);
                m_webSocket.sendTextMessage("bot1|11|0");
                delay(100);
                m_webSocket.sendTextMessage("bot1|12|0");
                delay(100);
                m_webSocket.sendTextMessage("bot1|13|0");
                

                }

                kshegunovK 1 Reply Last reply
                0
                • R Rahul Sharma

                  I have another issue with that . As string data is sending to server so i send integer value (1 to 10). And it is printing in client console one by one but if i look into server then after ending upto 10, then only it displays all counting suddenly(not displaying one by one). So is there something i m not sending the data to server correctly?

                  syntax is as follow -

                  void EchoClient::onConnected()
                  {

                     //m_webSocket.sendTextMessage("Hello sever");
                  
                  if (!m_debug)
                  
                      qDebug() << "WebSocket connected";
                  connect(&m_webSocket, &QWebSocket::textMessageReceived,
                          this, &EchoClient::onTextMessageReceived);
                  
                  for(int i=0; i<10;i++)
                   {
                      QString s = QString::number(i);
                  // QString data = Dialog::robotDataSendQueue.enqueue(QString("bot1|"+s+"|0"));
                  // data = Dialog::robotDataSendQueue.dequeue();
                  // qDebug() << "queu data" << data;
                  // m_webSocket.sendTextMessage(data);
                      qDebug()<< "s"<<s<<endl;
                      m_webSocket.sendTextMessage("bot1|"+s+"|0");
                     delay(500);
                  }
                  
                  m_webSocket.sendTextMessage("bot1|10|0");
                  delay(100);
                  m_webSocket.sendTextMessage("bot1|11|0");
                  delay(100);
                  m_webSocket.sendTextMessage("bot1|12|0");
                  delay(100);
                  m_webSocket.sendTextMessage("bot1|13|0");
                  

                  }

                  kshegunovK Offline
                  kshegunovK Offline
                  kshegunov
                  Moderators
                  wrote on last edited by
                  #8

                  @Rahul-Sharma said:

                  only it displays all counting suddenly(not displaying one by one)

                  With TCP/IP you have buffering, and data is not at all guaranteed to be read in separate packets. You have to account for that when writing your programs.

                  Read and abide by the Qt Code of Conduct

                  1 Reply Last reply
                  0
                  • R Offline
                    R Offline
                    Rahul Sharma
                    wrote on last edited by
                    #9

                    So can u plz suggest me how can i account that in my program? Bcz as just for information i have successfully transmitted data one by one in python websocket code. But in qtwebsocket default method for sending data to server is "m_websocket.sendTextMessage(string)" , so is there any other way to provide data in this method?

                    kshegunovK 1 Reply Last reply
                    0
                    • R Rahul Sharma

                      So can u plz suggest me how can i account that in my program? Bcz as just for information i have successfully transmitted data one by one in python websocket code. But in qtwebsocket default method for sending data to server is "m_websocket.sendTextMessage(string)" , so is there any other way to provide data in this method?

                      kshegunovK Offline
                      kshegunovK Offline
                      kshegunov
                      Moderators
                      wrote on last edited by kshegunov
                      #10

                      @Rahul-Sharma
                      I have not worked with QWebSocket, and it doesn't seem to provide synchronous operations (there doesn't seem to be any wait for write/read functions). I can only suggest to flush the data before each subsequent write.

                      Kind regards.

                      Read and abide by the Qt Code of Conduct

                      1 Reply Last reply
                      0
                      • R Offline
                        R Offline
                        Rahul Sharma
                        wrote on last edited by
                        #11

                        yes, Thanks @ kshegunov...I used flush and the problem is solved...

                        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