Page 1 of 2 12 LastLast
Results 1 to 20 of 24

Thread: QTcpServer problem receiving big files

  1. #1
    Join Date
    Jun 2010
    Posts
    100
    Thanks
    13
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QTcpServer problem receiving big files

    hi all!

    I am having some problem send/receiving large data files, 500 some kbytes.

    Code:
    Qt Code:
    1. QDataStream in(tcpSocket);
    2. in.setVersion(QDataStream::Qt_4_5);
    3.  
    4. forever {
    5. if (nextBlockSize == 0){
    6. if (tcpSocket->bytesAvailable() < sizeof (qint64))
    7. break;
    8. in >> nextBlockSize;
    9. cout << "Block size: " << QString::number(nextBlockSize).toStdString() << endl;
    10. }
    11.  
    12. if (tcpSocket->bytesAvailable() < nextBlockSize)
    13. {
    14. cout << "Going to break" << endl;
    15. break;
    16. }
    17.  
    18. ...
    To copy to clipboard, switch view to plain text mode 

    output:
    Qt Code:
    1. New connection
    2. DataReceived
    3. Block size: 611164
    4. Going to break
    5. DataReceived
    6. Block size: 34364522594
    7. Going to break
    8. DataReceived
    9. Block size: 28429488043851784
    10. Going to break
    11. DataReceived
    12. Block size: 23925866948264050
    13. Going to break
    14. DataReceived
    15. Block size: 214753804389
    16. Going to break
    17. DataReceived
    18. Block size: 32651449492373607
    19. Going to break
    20. DataReceived
    21. Block size: 29555366483460197
    22. Going to break
    23. DataReceived
    24. Block size: 32088581143265345
    25. Going to break
    26. DataReceived
    27. Block size: 31525678435008617
    28. Going to break
    29. DataReceived
    30. Block size: 27866439313784937
    31. Going to break
    32. DataReceived
    33. Block size: 31244194868822016
    34. Going to break
    35. DataReceived
    36. Block size: 2624568615239740
    37. Going to break
    38. DataReceived
    39. Block size: 13229757704634480
    40. Going to break
    41. DataReceived
    42. Block size: 13229637444436069
    43. Going to break
    44. DataReceived
    45. Block size: 33777284975165545
    46. Going to break
    47. DataReceived
    48. Block size: 28429445101781072
    49. Going to break
    To copy to clipboard, switch view to plain text mode 

    the DataReceived output means that the slot readyRead has been triggered, and the first Block size, with "611164 bytes" is the correct number.

    I think that I am getting multiple connections but I don't know how to do it better.
    I have looked to some examples but all look like mine.

  2. #2
    Join Date
    Aug 2009
    Location
    Belgium
    Posts
    310
    Thanks
    10
    Thanked 31 Times in 25 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTcpServer problem receiving big files

    Hi,

    How do you know that the first 4 bytes are the length of the file you are receiving, and when the first bytes of the file sent ? Is that on the sending side ?
    Anyway, I would do some sanity checking on that length. A size of 33777284975165545 seams unrealistic.

    Also, what do you do with the bytes when you are 'going to break' ? If it stays in the buffer, maybe you will read the length from this again the next time.

    Regards,
    Marc

  3. #3
    Join Date
    Jun 2010
    Posts
    100
    Thanks
    13
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QTcpServer problem receiving big files

    Hi,

    thank for your answer. I got this routine from website's examples and the qt book called "C++ Gui Programming with QT4". I know that the correct value is the 611164 because I check it on the client side.
    if I don't do the break the programm never stop, but once again I got this from websites.

    But basically there is no limitation to the size right??

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTcpServer problem receiving big files

    Do you read the data from the socket anywhere?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: QTcpServer problem receiving big files

    From my understanding of the posted code, when read in the following order:

    Qt Code:
    1. QDataStream in(tcpSocket);
    2. in.setVersion(QDataStream::Qt_4_5);
    3. in >> nextBlockSize;
    4. cout << "Block size: " << QString::number(nextBlockSize).toStdString() << endl;
    To copy to clipboard, switch view to plain text mode 

    This does not display the size.

  6. #6
    Join Date
    Jun 2010
    Posts
    100
    Thanks
    13
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QTcpServer problem receiving big files

    Quote Originally Posted by wysota View Post
    Do you read the data from the socket anywhere?
    yes, right after.

    Qt Code:
    1. QDataStream in(tcpSocket);
    2. in.setVersion(QDataStream::Qt_4_5);
    3.  
    4. forever {
    5. if (nextBlockSize == 0){
    6. if (tcpSocket->bytesAvailable() < sizeof (qint64))
    7. break;
    8. in >> nextBlockSize;
    9. cout << "Block size: " << QString::number(nextBlockSize).toStdString() << endl;
    10. }
    11.  
    12. if (tcpSocket->bytesAvailable() < nextBlockSize)
    13. {
    14. cout << "Going to break" << endl;
    15. break;
    16. }
    17.  
    18. in >> _applicationCall;
    19. in >> _classCall;
    20. in >> _methodCall;
    21. in >> _eBusinessObject;
    22. in >> qba;
    23. }
    To copy to clipboard, switch view to plain text mode 

    and this works if the qba (QByteArray) is small but when it's large like the one I want to store the server stops. Probably it waits until it receives data = 31525678435008617 bytes which means forever.

  7. #7
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: QTcpServer problem receiving big files

    No way.

    The server already read the whole file.
    You just don't display the size.

  8. #8
    Join Date
    Jun 2010
    Posts
    100
    Thanks
    13
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QTcpServer problem receiving big files

    the nextBlockSize variable is the size. It is a qint64 calculated on the client size

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTcpServer problem receiving big files

    Well, obviously what you display is not a correct size of the data. I would guess that once you exit the forever loop you exit the scope where "nextBlockSize" is defined and when you enter it back again after a subsequent readyRead() the variable gets reinitialized with random data.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  10. #10
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: QTcpServer problem receiving big files

    Those are not real sizes. You either do something wrong saving those sizes, or reading those sizes.

    Please, take a calculater and see how many terabytes those sizes are.

  11. #11
    Join Date
    Jun 2010
    Posts
    100
    Thanks
    13
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QTcpServer problem receiving big files

    Quote Originally Posted by wysota View Post
    Well, obviously what you display is not a correct size of the data. I would guess that once you exit the forever loop you exit the scope where "nextBlockSize" is defined and when you enter it back again after a subsequent readyRead() the variable gets reinitialized with random data.
    Exactly. I think that too. I just can't figure out why the I get multiple readyRead signals.

    First size is correct. the 600000 and some kbytes because I get the same value in the client side. After that I get all those random numbers that are a lot of terabytes

  12. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTcpServer problem receiving big files

    Quote Originally Posted by ruben.rodrigues View Post
    Exactly. I think that too. I just can't figure out why the I get multiple readyRead signals.
    Because in normal circumstances you can't fit 600kB in one IP packet. With 600kB you have to expect even 600k readyRead() signals.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  13. #13
    Join Date
    Jun 2010
    Posts
    100
    Thanks
    13
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QTcpServer problem receiving big files

    ok. Do you know how to solve this?

    I have made some changes and I got some values. The package size is 611000 Bytes and the value I am getting in my first connection is 4336 Bytes. That means I need about 140 connection. How do I overcome this.

  14. #14
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTcpServer problem receiving big files

    Quote Originally Posted by ruben.rodrigues View Post
    ok. Do you know how to solve this?
    Start by not copying code you don't understand. The forever loop in your code is already prepared for handling multiple readyRead() signals.

    How do I overcome this.
    It's not anything you have to overcome.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  15. #15
    Join Date
    Jun 2010
    Posts
    100
    Thanks
    13
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QTcpServer problem receiving big files

    Quote Originally Posted by wysota View Post
    Start by not copying code you don't understand. The forever loop in your code is already prepared for handling multiple readyRead() signals.


    It's not anything you have to overcome.
    I meant solve. My bad

  16. #16
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTcpServer problem receiving big files

    This is strictly a C++ related problem.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  17. #17
    Join Date
    Jun 2010
    Posts
    100
    Thanks
    13
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QTcpServer problem receiving big files

    so...Am I realy suppous to receive multiple readyRead signals?

  18. #18
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: QTcpServer problem receiving big files

    Quote Originally Posted by ruben.rodrigues View Post
    so...Am I realy suppous to receive multiple readyRead signals?
    Yes, you're supposed to get multiple ready read signals.

    First, read the entire data. Since it is a datastream, you might want to use the datastream only when it is complete read.

  19. #19
    Join Date
    Jun 2010
    Posts
    100
    Thanks
    13
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QTcpServer problem receiving big files

    Hi,

    I am trying to handle this but is not working and I am running out of ideas. Can someone explaining me how to be sure that all the data is received or tell me if there is an example that works with big packages and that I can look to?

    thanks

  20. #20
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTcpServer problem receiving big files

    Quote Originally Posted by ruben.rodrigues View Post
    Can someone explaining me how to be sure that all the data is received or tell me if there is an example that works with big packages and that I can look to?
    You already have that in your code!

    Qt Code:
    1. if (tcpSocket->bytesAvailable() < nextBlockSize)
    2. {
    3. cout << "Going to break" << endl;
    4. break;
    5. }
    To copy to clipboard, switch view to plain text mode 

    The only problem with your code is the "nextBlockSize" variable gets destroyed and loses its value and is initialized with a random value when the method is called again.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Problem with receiving Data from TcpSocket
    By Basti300 in forum Qt Programming
    Replies: 0
    Last Post: 15th July 2010, 14:41
  2. QTcpSocket, QTcpServer problem
    By frido in forum Qt Programming
    Replies: 3
    Last Post: 3rd April 2009, 23:16
  3. Qtcpserver problem
    By kingslee in forum Qt Programming
    Replies: 3
    Last Post: 3rd September 2008, 18:34
  4. Replies: 1
    Last Post: 18th June 2006, 10:12
  5. Problem with receiving events from QDateEdit
    By gunhelstr in forum Qt Programming
    Replies: 4
    Last Post: 20th April 2006, 11:21

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.