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

Bill Crocker william.crocker at analog.com
Wed Apr 27 17:24:23 CEST 2011


Jason H wrote:
> Why in the world are you doing that?
> 

> in >> buffer;

Because this will block until all of the data arrives
and his app may have better things to do?

Bill

> QDomDocument xml;
> xml.setContent(buffer.toString());
> 
> 
> 
> 
> 
> ----- Original Message ----
> From: franki <franki at franki.eu.org>
> To: qt-interest at trolltech.com
> Sent: Wed, April 27, 2011 10:08:35 AM
> Subject: [Qt-interest] large xml over the network - problem
> 
> 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;/net/neuro/disk1/apache/website/htdocs/adice/adiceinfo/log_r10.txt
>         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
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at qt.nokia.com
> http://lists.qt.nokia.com/mailman/listinfo/qt-interest
> 
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at qt.nokia.com
> http://lists.qt.nokia.com/mailman/listinfo/qt-interest
> 





More information about the Qt-interest-old mailing list