Hi Esquive
I have solved the problem almost. Now I am able to send Large files over network.
problem in my previous code was that I was closing the file before it was completely written.
If you like you can have a look at these samples.
with these codes i am able to send data of upto 300 mb on windows platform.
if you want to send larger files try sending them in chunks.
//sender code
{
//create a socket in serevr side
QTcpSocket *clientConnection = tcpServer->nextPendingConnection();
connect(clientConnection, SIGNAL(disconnected()),
clientConnection, SLOT(deleteLater()));
//code for reading the file
QFile inputFile("path to file to be read");
inputFile.open(QIODevice::ReadOnly);
QByteArray block;
QDataStream out(&block, QIODevice::WriteOnly);
out.setVersion(QDataStream::Qt_4_0);
out << (quint32)0;
QByteArray qwerty=inputFile.readAll();
block.append(qwerty);
inputFile.close();
out.device()->seek(0);
out << (quint32)(block.size() - sizeof(quint32));
qint64 x=0;
while(x<block.size())
{
qint64 y=clientConnection->write(block);
x=x+y;
qDebug()<<x;
}
clientConnection->disconnectFromHost();
}
//receiver code
{
QDataStream in(tcpSocket);
in.setVersion(QDataStream::Qt_4_0);
if (blockSize == 0)
{
if (tcpSocket->bytesAvailable() < sizeof(quint32))
return ;
in >> blockSize;
}
if (tcpSocket->bytesAvailable() < blockSize)
return ;
QByteArray line;
line= tcpSocket -> readAll();
QFile file("D:/drdo/qt_apps/done/june1/client/x.avi");
if(!(file.open(QIODevice::Append)))
QMessageBox::information(this, tr("File"),tr("File cannot be opened."));
file.write(line);
blockSize=0;
file.close();
}