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.

  • Qt Echoclient Websocket Connetion done but No data sending.

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

  • 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.

  • 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.

  • @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.

  • 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".

  • 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;


  • Qt Champions 2017

    @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.

  • 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?

  • Qt Champions 2017

    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.

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

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.