Originally Posted by
Vit Stepanek
Obviously the problem is, QTcpSocket works asynchronously, so calling "write" just puts your data to a buffer but sending occurs independently. Since the copying data to a buffer in your code is certainly faster, you fill the buffer with all data earlier than the data are sent.
Put "waitForBytesWritten" call after the write command if you need to wait with the next write step until the data are sent.
Ok thanks, now my program working correct.
Note that this blocks and it should only be used when no event loop is available (like in a thread with no event loop)
Just send 50 messages and read them at the other side. How hard can this be, just make sure you can seperate them in some way.
Use a QXmlStreamReader and Writer, then you don't have to care about headers or control characters to split the messages.
There isn't a problem because I don't have Gui application.
Now I have another problem:
Memory use by client is constantly increase and I have a memory overflow.
I have try with flush instruction but I don't have solve this problem.
QtcpSocket store some information?
This is my client code:
Qt code
[code]
QString xInfo
xInfo = pxSocket->readAll();
[code]
I try to use a QByteArray but this code don't work proprerly:
(Server code)
1 for (int i = 0; i < xDataStringList.size(); i++)
2 {
6 xOut << (quint16)0;
7 xOut << xDataStringList.at(i);
8 xOut.device()->seek(0);
9 xOut << (quint16)(xBlock.size() - sizeof(quint16));
10 pxTransmissionSocket->write(xBlock);
}
1 for (int i = 0; i < xDataStringList.size(); i++)
2 {
3 QByteArray xBlock;
4 QDataStream xOut(&xBlock, QIODevice::WriteOnly);
5 xOut.setVersion(QDataStream::Qt_4_0);
6 xOut << (quint16)0;
7 xOut << xDataStringList.at(i);
8 xOut.device()->seek(0);
9 xOut << (quint16)(xBlock.size() - sizeof(quint16));
10 pxTransmissionSocket->write(xBlock);
}
To copy to clipboard, switch view to plain text mode
xBlock at line 10 is empty.
Thanks, bye
Bookmarks