Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. qt file uploading, Connection closed error
QtWS25 Last Chance

qt file uploading, Connection closed error

Scheduled Pinned Locked Moved Solved General and Desktop
13 Posts 2 Posters 3.7k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Stoyan

    @4j1th
    I'm not sure if this is the reason, but you created a lot of objects QNetworkAccessManager and QNetworkReply and never delete them. According to documentation:
    "One QNetworkAccessManager should be enough for the whole Qt application."
    "Currently, for the HTTP protocol on desktop platforms, 6 requests are executed in parallel for one host/port combination."
    May be it is better to make QNetworkAccessManager member of the class myServer and to not create new object in uploadFiles.

    QNetworkAccessManager *manager;  // in header file
    
    manager = new QNetworkAccessManager();  // In the constructor of myServer
    
    myServer::uploadFiles()
    ...
    QNetworkReply *reply = manager->post(request, multiPart);
    

    And to delete QNetworkReply objects:

    fileUploadFinished(QNetworkReply *replay)
    ...
    replay->close();
    replay->deleteLater();
    

    And what is doing the slot waitupload()?

    4 Offline
    4 Offline
    4j1th
    wrote on last edited by
    #4

    @Stoyan

    waitupload() - used as a workaround of this error, the execution waits 20 seconds and continue the upload and it works as i said in my question

    Pardon my English
    Thank you.

    S 1 Reply Last reply
    0
    • S Stoyan

      @4j1th
      I'm not sure if this is the reason, but you created a lot of objects QNetworkAccessManager and QNetworkReply and never delete them. According to documentation:
      "One QNetworkAccessManager should be enough for the whole Qt application."
      "Currently, for the HTTP protocol on desktop platforms, 6 requests are executed in parallel for one host/port combination."
      May be it is better to make QNetworkAccessManager member of the class myServer and to not create new object in uploadFiles.

      QNetworkAccessManager *manager;  // in header file
      
      manager = new QNetworkAccessManager();  // In the constructor of myServer
      
      myServer::uploadFiles()
      ...
      QNetworkReply *reply = manager->post(request, multiPart);
      

      And to delete QNetworkReply objects:

      fileUploadFinished(QNetworkReply *replay)
      ...
      replay->close();
      replay->deleteLater();
      

      And what is doing the slot waitupload()?

      4 Offline
      4 Offline
      4j1th
      wrote on last edited by 4j1th
      #5

      @Stoyan I think this post solves the new object issue

      https://stackoverflow.com/questions/23267925/when-to-delete-qnetworkaccessmanager-pointer

      // Delete object whose signal triggered this slot.
          QObject *manager = sender();
          manager->deleteLater();
      

      But this doesn't solve the connection error issue

      Pardon my English
      Thank you.

      1 Reply Last reply
      0
      • 4 4j1th

        @Stoyan

        waitupload() - used as a workaround of this error, the execution waits 20 seconds and continue the upload and it works as i said in my question

        S Offline
        S Offline
        Stoyan
        wrote on last edited by
        #6

        @4j1th
        Did you add

        replay->deleteLater();
        

        What is the result of replay->errorString(); ?
        The code you post should work if you create instance of QNetworkAccessManager every time.
        Did you left in code this row:

        QNetworkAccessManager * manager = new QNetworkAccessManager();
        

        Did you call function uploadFiles() from multiple places?
        I suspect that you create multiple connection to server and there is a limitation for such activity.

        1 Reply Last reply
        0
        • 4 4j1th

          @Stoyan Thanks for the replay

          I tried you said but it save same file copy multiple times in server and don't return the send post data in order

          S Offline
          S Offline
          Stoyan
          wrote on last edited by Stoyan
          #7

          @4j1th said in qt file uploading, Connection closed error:

          @Stoyan Thanks for the replay

          I tried you said but it save same file copy multiple times in server and don't return the send post data in order

          I think I understand why this happens. Try to move this row

          connect(manager, SIGNAL(finished(QNetworkReply*)), SLOT(fileUploadFinished(QNetworkReply*)));
          

          in the constructor, right after this:

          manager = new QNetworkAccessManager();
          

          Else it creates multiple connections for one object.

          4 1 Reply Last reply
          2
          • S Stoyan

            @4j1th said in qt file uploading, Connection closed error:

            @Stoyan Thanks for the replay

            I tried you said but it save same file copy multiple times in server and don't return the send post data in order

            I think I understand why this happens. Try to move this row

            connect(manager, SIGNAL(finished(QNetworkReply*)), SLOT(fileUploadFinished(QNetworkReply*)));
            

            in the constructor, right after this:

            manager = new QNetworkAccessManager();
            

            Else it creates multiple connections for one object.

            4 Offline
            4 Offline
            4j1th
            wrote on last edited by 4j1th
            #8

            @Stoyan now it's working but still generate the "Connection closed" error from 'replay->errorString();'

            Pardon my English
            Thank you.

            S 1 Reply Last reply
            0
            • 4 4j1th

              @Stoyan now it's working but still generate the "Connection closed" error from 'replay->errorString();'

              S Offline
              S Offline
              Stoyan
              wrote on last edited by Stoyan
              #9

              @4j1th
              Can you put in the beginning of fileUploadFinished, before checking for errors, this code:

              QByteArray strreplay = replay->readAll();
              qDebug() << "Reply: " << strreplay;
              qDebug() << "Reply error code: " << replay->error();
              

              Maybe there is some informative response to some of the requests before terminating connection.
              This is the list with all error codes: QNetworkReply::NetworkError

              4 2 Replies Last reply
              1
              • S Stoyan

                @4j1th
                Can you put in the beginning of fileUploadFinished, before checking for errors, this code:

                QByteArray strreplay = replay->readAll();
                qDebug() << "Reply: " << strreplay;
                qDebug() << "Reply error code: " << replay->error();
                

                Maybe there is some informative response to some of the requests before terminating connection.
                This is the list with all error codes: QNetworkReply::NetworkError

                4 Offline
                4 Offline
                4j1th
                wrote on last edited by 4j1th
                #10

                @Stoyan thank you for that debugging idea

                "uploading : 2017_06_18_00_00_00_26/raw/8/images/mUarFdVu5ZZmiOqFjLoTz4lXn.JPG"
                Reply:  "27"
                Reply error code:  QNetworkReply::NetworkError(NoError)
                "upload sucessfull 27"
                "uploading : 2017_06_18_00_00_00_26/raw/8/images/sj0DMlogCTmdoUZEtBk8pph0R.JPG"
                Reply:  "28"
                Reply error code:  QNetworkReply::NetworkError(NoError)
                "upload sucessfull 28"
                "uploading : 2017_06_18_00_00_00_26/raw/8/images/0nMaAxIhlJtNxOPHystIFv2EW.JPG"
                Reply:  "29"
                Reply error code:  QNetworkReply::NetworkError(NoError)
                "upload sucessfull 29"
                "uploading : 2017_06_18_00_00_00_26/raw/8/images/0t9VhPJKZjIMppyzZBknOpb4Z.JPG"
                Reply:  "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\n<html><head>\n<title>408 Request Timeout</title>\n</head><body>\n<h1>Request Timeout</h1>\n<p>Server timeout waiting for the HTTP request from the client.</p>\n<p>Additionally, a 408 Request Timeout\nerror was encountered while trying to use an ErrorDocument to handle the request.</p>\n</body></html>\n"
                Reply error code:  QNetworkReply::NetworkError(UnknownContentError)
                "Error transferring http://client.mydomain.com/index.php/update/upload_files - server replied: Request Timeout"
                

                Pardon my English
                Thank you.

                1 Reply Last reply
                0
                • S Stoyan

                  @4j1th
                  Can you put in the beginning of fileUploadFinished, before checking for errors, this code:

                  QByteArray strreplay = replay->readAll();
                  qDebug() << "Reply: " << strreplay;
                  qDebug() << "Reply error code: " << replay->error();
                  

                  Maybe there is some informative response to some of the requests before terminating connection.
                  This is the list with all error codes: QNetworkReply::NetworkError

                  4 Offline
                  4 Offline
                  4j1th
                  wrote on last edited by
                  #11

                  @Stoyan another error now I get is

                  Reply error code: QNetworkReply::NetworkError(RemoteHostClosedError)

                  Pardon my English
                  Thank you.

                  S 1 Reply Last reply
                  0
                  • 4 4j1th

                    @Stoyan another error now I get is

                    Reply error code: QNetworkReply::NetworkError(RemoteHostClosedError)

                    S Offline
                    S Offline
                    Stoyan
                    wrote on last edited by
                    #12

                    @4j1th
                    If error "RemoteHostClosedError" follow the previous error "UnknownContentError", probably the reason is the first error.
                    You may run the program some more times to collect more data and contact again your service provider with this information.
                    It is possible to exists some limitation on your account. For example: number of transferred files for a period. Some servers after too many requests for a short time, ask for some type additional identification (captcha for example).

                    And one more thing (not directly connected to the main problem) - you should close and delete the instance of "replay" even when an error occurred.

                    4 1 Reply Last reply
                    1
                    • S Stoyan

                      @4j1th
                      If error "RemoteHostClosedError" follow the previous error "UnknownContentError", probably the reason is the first error.
                      You may run the program some more times to collect more data and contact again your service provider with this information.
                      It is possible to exists some limitation on your account. For example: number of transferred files for a period. Some servers after too many requests for a short time, ask for some type additional identification (captcha for example).

                      And one more thing (not directly connected to the main problem) - you should close and delete the instance of "replay" even when an error occurred.

                      4 Offline
                      4 Offline
                      4j1th
                      wrote on last edited by
                      #13

                      @Stoyan thanks for the help, I also think that this is a server limitation issue I am trying to resolve the issue with Godaddy, mean time I think the workaround is useful.

                      Pardon my English
                      Thank you.

                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved