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. Stream XML Data over TCP
Forum Updated to NodeBB v4.3 + New Features

Stream XML Data over TCP

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 1.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.
  • G Offline
    G Offline
    Guju
    wrote on last edited by
    #1

    Hi!
    I want to stream XML data from a server. The server sends the data(server time) ever few seconds. If i send the command <all/> the server sends a lot of XML data over the next time. To create the connection to server and send the <ALL/> command works finde. I also get the first data pack with the following code:

    socket->connectToHost(Server, Port);
       if(socket->waitForConnected(3000))
        {
            qDebug() << "Connected!";
            socket->write("<all/>");
            socket->waitForBytesWritten(1000);
            socket->waitForReadyRead(3000);
            qDebug() << "Reading: " << socket->bytesAvailable();
            qDebug() << socket->readAll();
            socket->close();
            return "Connected";
        }
    If i want to get all the following data i created a Signal/Slot code.With this i want to read data as soon as it is sent from the server:
    

    connect(socket, SIGNAL(connected()),this, SLOT(connected()));
    connect(socket, SIGNAL(disconnected()),this, SLOT(disconnected()));
    connect(socket, SIGNAL(bytesWritten(qint64)),this, SLOT(bytesWritten(qint64)));
    connect(socket, SIGNAL(readyRead()),this, SLOT(readyRead()));
    ....
    void SocketTest::connected()
    {
    qDebug() << "connected...slot";
    // socket->write("<all/>");
    }

    void SocketTest::readyRead()
    {
    qDebug() << "Reading: " << socket->bytesAvailable();
    qDebug() << socket->readAll();
    }
    This code does not work. I do not get the ready read signal and no data from the server. Sorry for bothering you with that simple question, but i can not solve the problem...Thanks for your help Juergen

    K jsulmJ 2 Replies Last reply
    0
    • G Guju

      Hi!
      I want to stream XML data from a server. The server sends the data(server time) ever few seconds. If i send the command <all/> the server sends a lot of XML data over the next time. To create the connection to server and send the <ALL/> command works finde. I also get the first data pack with the following code:

      socket->connectToHost(Server, Port);
         if(socket->waitForConnected(3000))
          {
              qDebug() << "Connected!";
              socket->write("<all/>");
              socket->waitForBytesWritten(1000);
              socket->waitForReadyRead(3000);
              qDebug() << "Reading: " << socket->bytesAvailable();
              qDebug() << socket->readAll();
              socket->close();
              return "Connected";
          }
      If i want to get all the following data i created a Signal/Slot code.With this i want to read data as soon as it is sent from the server:
      

      connect(socket, SIGNAL(connected()),this, SLOT(connected()));
      connect(socket, SIGNAL(disconnected()),this, SLOT(disconnected()));
      connect(socket, SIGNAL(bytesWritten(qint64)),this, SLOT(bytesWritten(qint64)));
      connect(socket, SIGNAL(readyRead()),this, SLOT(readyRead()));
      ....
      void SocketTest::connected()
      {
      qDebug() << "connected...slot";
      // socket->write("<all/>");
      }

      void SocketTest::readyRead()
      {
      qDebug() << "Reading: " << socket->bytesAvailable();
      qDebug() << socket->readAll();
      }
      This code does not work. I do not get the ready read signal and no data from the server. Sorry for bothering you with that simple question, but i can not solve the problem...Thanks for your help Juergen

      K Offline
      K Offline
      koahnig
      wrote on last edited by koahnig
      #2

      @Guju

      As already answered in your German post.

      The problem is the size of the data which cannot be known by the TCP socket. The readyRead signal is triggered when data has been received. It cannot be determined in QTcpSocket when all data has been received.

      Vote the answer(s) that helped you to solve your issue(s)

      1 Reply Last reply
      3
      • G Guju

        Hi!
        I want to stream XML data from a server. The server sends the data(server time) ever few seconds. If i send the command <all/> the server sends a lot of XML data over the next time. To create the connection to server and send the <ALL/> command works finde. I also get the first data pack with the following code:

        socket->connectToHost(Server, Port);
           if(socket->waitForConnected(3000))
            {
                qDebug() << "Connected!";
                socket->write("<all/>");
                socket->waitForBytesWritten(1000);
                socket->waitForReadyRead(3000);
                qDebug() << "Reading: " << socket->bytesAvailable();
                qDebug() << socket->readAll();
                socket->close();
                return "Connected";
            }
        If i want to get all the following data i created a Signal/Slot code.With this i want to read data as soon as it is sent from the server:
        

        connect(socket, SIGNAL(connected()),this, SLOT(connected()));
        connect(socket, SIGNAL(disconnected()),this, SLOT(disconnected()));
        connect(socket, SIGNAL(bytesWritten(qint64)),this, SLOT(bytesWritten(qint64)));
        connect(socket, SIGNAL(readyRead()),this, SLOT(readyRead()));
        ....
        void SocketTest::connected()
        {
        qDebug() << "connected...slot";
        // socket->write("<all/>");
        }

        void SocketTest::readyRead()
        {
        qDebug() << "Reading: " << socket->bytesAvailable();
        qDebug() << socket->readAll();
        }
        This code does not work. I do not get the ready read signal and no data from the server. Sorry for bothering you with that simple question, but i can not solve the problem...Thanks for your help Juergen

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #3

        @Guju In connected() slot you commented out socket->write("<all/>");

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        1

        • Login

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