Hi All,

I am developing a LAN application using Qt on Windows, I need to send a database file from clients to the server but I am unable to send the file properly the server is only receiving incomplete file or only signature of file which I am able to see in the destination folder but the file is empty.


The server code is:
Qt Code:
  1. void Mainapp::newConnection()
  2. {
  3. QTcpSocket *socket = server->nextPendingConnection();
  4. QFile file("C:/Qt/DB2");
  5. file.remove();
  6. file.open(QIODevice::Append);
  7. socket->waitForReadyRead(1000);
  8. qDebug()<<"hello kitty";
  9. while(socket->bytesAvailable())
  10. {
  11. qDebug()<<"yes";
  12. QByteArray bytes = socket->readLine();
  13. file.write(bytes);
  14. }
  15.  
  16.  
  17.  
  18.  
  19. socket->close();
  20. }
  21.  
  22. void Mainapp::broadcastDatagram()
  23. {
  24.  
  25. QString str;
  26. foreach (const QHostAddress &address, QNetworkInterface::allAddresses()) {
  27. if (address.protocol() == QAbstractSocket::IPv4Protocol && address != QHostAddress(QHostAddress::LocalHost))
  28. {
  29.  
  30. udpSocket->writeDatagram("127.0.0.1", QHostAddress::Broadcast, 45454);
  31. }
  32. }
  33. }
To copy to clipboard, switch view to plain text mode 

The client code is:
Qt Code:
  1. void Datafeed::connected()
  2. {
  3. qDebug()<<"Connected...";
  4. QFile myFile("C:/Qt/DB");
  5. myFile.open(QIODevice::ReadOnly);
  6. QByteArray data= myFile.readAll();
  7. QByteArray block;
  8.  
  9. QDataStream out(&block, QIODevice::WriteOnly);
  10.  
  11.  
  12. out << (quint32)0;
  13.  
  14. out.device()->seek(0);
  15. out << (quint32)(block.size() - sizeof(quint32));
  16.  
  17. msocket->write(data);
  18. qDebug()<<data.data();
  19.  
  20.  
  21. }
To copy to clipboard, switch view to plain text mode 

Thanks in advance for any help.