Results 1 to 5 of 5

Thread: QTcpSocket disconnection problem

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2006
    Posts
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTcpSocket disconnection problem

    Qt Code:
    1. QFile file(filePath + "/" + fileName);
    2. file.open(QIODevice::ReadOnly);
    3. QByteArray byteArray;
    4.  
    5. while (numberOfPackages > 0){
    6. byteArray = file.read(1024);
    7. numberOfPackages--;
    8.  
    9. if(sock->state()!=QAbstractSocket::ConnectedState){
    10. printf("Socket disconnected error\n");
    11. return;
    12. }
    13.  
    14. sock->write(byteArray);
    15.  
    16.  
    17. if (sock->bytesToWrite() > 0 && !sock->waitForBytesWritten(10000)){
    18. printf("Socket write error\n");
    19. printf("socket error: %d %s, socket state: %d\n", sock->error(), sock->errorString().toAscii().data(),
    20.  
    21. sock->state());
    22. return;
    23. }
    24.  
    25. }
    To copy to clipboard, switch view to plain text mode 

    As I said the second if statement is executed after sending about 50KB of data.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    28
    Thanked 976 Times in 912 Posts

    Default Re: QTcpSocket disconnection problem

    I've tried your code and I was able to send 100kB file without any problems.

    Does it wait 10 seconds before printing that "Socket write error" message?

  3. #3
    Join Date
    Feb 2006
    Posts
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTcpSocket disconnection problem

    I've found that the socket worked wrong because it was created by QTcpServer in one thread and I was using it in another one, in a class inheriting the QThread socket. When I send something in the same thread that socket was created in it works fine...

    It is still a strange situation form me...

Similar Threads

  1. Problem in printing the data return /read from QTcpsocket
    By skumar434 in forum Qt Programming
    Replies: 3
    Last Post: 20th February 2009, 19:36
  2. Challenging QTcpSocket reliability problem
    By Raccoon29 in forum Qt Programming
    Replies: 3
    Last Post: 13th January 2009, 10:38
  3. Problem in QTcpSocket
    By navi1084 in forum Qt Programming
    Replies: 2
    Last Post: 16th October 2008, 12:12
  4. Problem with QTcpSocket in QThread
    By Raistlin in forum Qt Programming
    Replies: 8
    Last Post: 6th October 2007, 12:23
  5. problem with QTcpSocket
    By SuperSonik in forum Qt Programming
    Replies: 8
    Last Post: 31st January 2007, 16:00

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
  •  
Qt is a trademark of The Qt Company.