Unsolved Stream XML Data over TCP
-
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 -
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.
-
@Guju In connected() slot you commented out socket->write("<all/>");