PDA

View Full Version : How to "CLEAR" data on QTcpSocket



wirasto
28th June 2010, 13:01
Can I clear data on tcpSocket without read it ?

I tried like this but still not working.


qDebug() << myTcpSocket->size(); //result 3229696
myTcpSocket->reset();
qDebug() << myTcpSocket->size(); //result 3229696


If like this, is working. But, make a delay if data size is big.


qDebug() << myTcpSocket->size(); //result 3229696
myTcpSocket->readAll();
qDebug() << myTcpSocket->size(); //result 0


Thank's before..

tbscope
29th June 2010, 05:38
To clear the buffer of the TCP socket, you need to read it.
But, if the socket can still receive data, it will fill the buffer again, and again, till everything is received. Thus, also close the connection before reading the buffer for the last time.

If the data is received in large blocks, you can set the read buffer size to receive smaller data blocks. This will generate more overhead that gets more significant the smaller the blocks are.