[Qt-interest] large xml over the network - problem
Jeroen.DeWachter at elis.UGent.be
Jeroen.DeWachter at elis.UGent.be
Wed Apr 27 16:23:22 CEST 2011
Hi,
You do know quint16 is limited to 65536, right?
So if you're using strings that are longer than that (and you seem to do
just that, judging from your example), the length can't be specified
correctly in the two bytes you are trying to use for it...
That would certainly be an explanation for the huge discrepancy in your
block size and the quint size...
Kind regards,
Jeroen
Quoting franki <franki at franki.eu.org>:
> 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
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at qt.nokia.com
> http://lists.qt.nokia.com/mailman/listinfo/qt-interest
>
----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.
More information about the Qt-interest-old
mailing list