I want to send a large file using qt's socket programming for this is edited the existing fortune client-server code as follows:

Server code:-

void Server::SendData()
{
QByteArray block;
QByteArray data;
QDataStream out(&block, QIODevice::WriteOnly);
out.setVersion(QDataStream::Qt_4_0);
while(1)
{
out << quint64(0);
data = inputFile.read(32768*8);
qDebug() << "Read : " << data.size();
if(data.size()==0)
break;
out << data;
out.device()->seek(0);
out << quint64(block.size() - sizeof(quint64));
client.write(block);
qDebug() << "Written : " << block.size();
//block.clear();
}
client.disconnectFromHost();
client.waitForDisconnected();
}

Client Code:-

void Client::ReadData()
{
QFile file(filename);
if(!(file.open(QIODevice::Append)))
{
qDebug("File cannot be opened.");
exit(0);
}

QDataStream in(client);
QByteArray data;
in.setVersion(QDataStream::Qt_4_0);


if (blockSize == 0) {
if (client->bytesAvailable() < sizeof(quint64))
return;
in >> blockSize;
}

if (client->bytesAvailable() < blockSize)
return;

data = client->readAll();
file.write(data);
qDebug() << "Written : " << data.size() ;
blockSize = 0;
file.close();
}

So according to documentation whenever data is available on socket the readyRead() signal is emitted, i have connected Slot ReadData() to it.
The problem is full file is not transferred on the client side ,lot of data is missing(tested 1.3 G, only 1.2 G was received)
Can any one please tell what is wrong in the above code?