PDA

View Full Version : QTcpSocket reading by chunk



stef13013
6th September 2012, 18:24
Hello,

With a "classic" network behaviour, a read() function must be -sometimes- called many times because packets aren't delivered in one chunk
eg:


int siz=2048;
int len=siz;

while(len>0)
{
siz = read(socket, len); // returns number of bytes read

if (siz==0)
return 1;

len-=siz;
}


Now, with QTcpSocket, do I have the same "problem" or a simple
sck.read(socket, len);
is enough to get all the data "len"gth ?


Thanks

wysota
8th September 2012, 06:07
As with any other TCP traffic, you have the same "problem". However instead of such a while loop, you should rely on signals emitted by the socket object.