void Server::onReadyRead()
{
if(data == Size_of_Data)
{
QTextStream(stdout) <<
" Entering the slot = "<<a
++ <<endl;
buffer.append(clientSocket->readAll());
while(buffer.size() >=4)
{
quint32 blockSize = buffer.at(0) << 24 | buffer.at(1) << 16 | buffer.at(2) << 8 | buffer.at(3); // or similar, e.g. qFromBigEndian
QTextStream(stdout) <<
" before IF buffer = "<<buffer.
size() <<endl;
QTextStream(stdout) <<
" before IF blockSize = "<<sizeof
(blockSize
)<<endl;
if(buffer.size()>=4+blockSize)
{
buffer = buffer.mid(4+blockSize);
QTextStream(stdout) <<
" in IF data = "<<data.
size() <<endl;
QTextStream(stdout) <<
" in IF buffer = "<<buffer.
size() <<endl;
//processData(data);
}
else
{
QTextStream(stdout) <<
" on output buffer.size = "<<buffer.
size() <<endl;
return;
}
}
}
else if(data == Exact_Data)
{
}
}
void Server::onReadyRead()
{
if(data == Size_of_Data)
{
QTextStream(stdout) << " Entering the slot = "<<a++ <<endl;
buffer.append(clientSocket->readAll());
while(buffer.size() >=4)
{
QTextStream(stdout) << " in while = "<<b++ <<endl;
quint32 blockSize = buffer.at(0) << 24 | buffer.at(1) << 16 | buffer.at(2) << 8 | buffer.at(3); // or similar, e.g. qFromBigEndian
QTextStream(stdout) << " before IF buffer = "<<buffer.size() <<endl;
QTextStream(stdout) << " before IF blockSize = "<<sizeof(blockSize)<<endl;
if(buffer.size()>=4+blockSize)
{
QTextStream(stdout) << " entering IF = "<<c++ <<endl;
QByteArray data = buffer.mid(4,blockSize);
buffer = buffer.mid(4+blockSize);
QTextStream(stdout) << " in IF data = "<<data.size() <<endl;
QTextStream(stdout) << " in IF buffer = "<<buffer.size() <<endl;
//processData(data);
}
else
{
QTextStream(stdout) << " on output buffer.size = "<<buffer.size() <<endl;
return;
}
}
}
else if(data == Exact_Data)
{
QTextStream(stdout) << "getting the right data"<<endl;
}
}
To copy to clipboard, switch view to plain text mode
I wrote sth like this, but i don't know exactle when I should pull out the right buffer.size out of the slot (to use it for expecting the incomimg file data)becouse, I've run a simple test and got:
Entering the slot = 0
in while = 0
before IF buffer = 4096
before IF blockSize = 4
entering IF = 0
in IF data = 0
in IF buffer = 4092
in while = 1
before IF buffer = 4092
before IF blockSize = 4
on output buffer.size = 4092
Entering the slot = 1
in while = 2
before IF buffer = 8188
before IF blockSize = 4
on output buffer.size = 8188
Entering the slot = 2
in while = 3
before IF buffer = 8848
before IF blockSize = 4
on output buffer.size = 8848
Entering the slot = 0
in while = 0
before IF buffer = 4096
before IF blockSize = 4
entering IF = 0
in IF data = 0
in IF buffer = 4092
in while = 1
before IF buffer = 4092
before IF blockSize = 4
on output buffer.size = 4092
Entering the slot = 1
in while = 2
before IF buffer = 8188
before IF blockSize = 4
on output buffer.size = 8188
Entering the slot = 2
in while = 3
before IF buffer = 8848
before IF blockSize = 4
on output buffer.size = 8848
To copy to clipboard, switch view to plain text mode
Bookmarks