[Qt-interest] large xml over the network - problem

franki franki at franki.eu.org
Wed Apr 27 16:08:35 CEST 2011


Hi all,

I have client-server application which exchange data using xml's over the net.
With relatively small xml's everything goes fine, but when I try to send big 
ones there is problem with receiving it (not always just from time to time), 
and if I double the size of xml, they are always lost.
Snippet of code on server side:

void NetThread::sendToClient(QDomDocument xml) {
    QByteArray block;
    QDataStream out(&block, QIODevice::ReadWrite);
    out.setVersion(QDataStream::Qt_4_0);
    out << (quint16)0;
    out << xml.toString();
    out.device()->seek(0);
    out << (quint16)(block.size() - sizeof(quint16));
    qDebug() <<" quint size:"<<(quint16)(block.size() - sizeof(quint16))
    qDebug() <<" block size:"<<block.size();
    qDebug() <<" string size:"<<xml.toString().size();
    tcpSocket->write(block);
}

code on client side look's like this (dataSize is quint16):
void NetManager::readData() {
    QDataStream in(socket);
    in.setVersion(QDataStream::Qt_4_0);
    if (dataSize == 0) {
        if (socket->bytesAvailable() < (int)sizeof(quint16))
            return;
        in >> dataSize;
    }
    if(socket->bytesAvailable() < dataSize)
             return;

    QString text;
    in >> text;
    qDebug() << " dataSize:"<<dataSize<<" received:"<<text;
    dataSize=0;
    this->parseData(text);
    if(socket->bytesAvailable())
        this->readData();
}

On the server side, during transmission debug says:
quint size: 3958 
block size: 69496
string size: 34745

On client side when there is successful transmision I got:
NetManager::readData dataSize: 3958  received: "very long_xml_string"

When there is problem with transmission I got:
Debug: NetManager::readData bytes: 3958  received: "" 
Debug: NetManager::parseData parse error 
Debug: NetManager::readData bytes: 61  received: "" 
Debug: NetManager::parseData parse error 
Debug: NetManager::readData bytes: 51  received: "" 
Debug: NetManager::parseData parse error 
Debug: NetManager::readData bytes: 56  received: "" 
Debug: NetManager::parseData parse error 

So in second example the packet length is the same 3958 but the function is 
called 4 times and I'm quite sure that application on server side doesn't 
send anything except for this xml.
So please can someone point me on my errors?

best regards
Marek



More information about the Qt-interest-old mailing list