Results 1 to 2 of 2

Thread: Unable to send database file over LAN

  1. #1
    Join Date
    Oct 2013
    Posts
    7
    Thanks
    2
    Qt products
    Qt5 Qt Jambi
    Platforms
    Unix/X11 Windows Android

    Default Unable to send database file over LAN

    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.

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Unable to send database file over LAN

    You are assuming that the entire file arrives and is announced by a single readyRead() signal. This will not be the case and is the cause of your truncated file.
    You are also treating your incoming data stream as if it was text, (e.g. With readline()) which is at odds with the QDataStream you used at the other end.

Similar Threads

  1. Unable to work with database
    By Atomic_Sheep in forum Newbie
    Replies: 9
    Last Post: 18th August 2013, 19:17
  2. Replies: 1
    Last Post: 12th April 2013, 20:46
  3. Unable to send SMS
    By Manjula in forum Newbie
    Replies: 0
    Last Post: 11th March 2011, 12:40
  4. Replies: 9
    Last Post: 20th May 2010, 10:55
  5. How can I send a SQLite :memory: database connection ?
    By georgep in forum Qt Programming
    Replies: 4
    Last Post: 20th July 2009, 13:07

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.