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. QStateMachine/Networking best practice
Forum Updated to NodeBB v4.3 + New Features

QStateMachine/Networking best practice

Scheduled Pinned Locked Moved Solved General and Desktop
11 Posts 3 Posters 3.2k Views 1 Watching
  • 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.
  • B Offline
    B Offline
    brunjak
    wrote on last edited by
    #1

    Hi,
    I want to design a ftp client. FTP is specified in rfc959. Sending ftp-commands and receiving the reply-codes use state machines.

    My state machine (QStateMachine) is running in the QApplication main thread. There are four states:

    • sendCommand
    • waitForReply
    • Success
    • Error

    In the socket (QTcpSocket) i'm using signals and slots.

    In the state "waitForReply" i have to wait until response is ready to read in the socket. What would be the best practice to realize this. Should i use threads in combination with waitconditions? Or is there a simple solution without an extra thread? My goal is to keep it event triggered.

    Thank you
    Jakob

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

      Do you need to build it manually? QNetworkAccessManager can manage FTP already out of the box

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      B 1 Reply Last reply
      0
      • VRoninV VRonin

        Do you need to build it manually? QNetworkAccessManager can manage FTP already out of the box

        B Offline
        B Offline
        brunjak
        wrote on last edited by
        #3

        @VRonin

        Thank you for the response. In this case I could use QNetworkAccessManager. In another project I will need a communication channel with customized port/protocol. Could I also use QNetworkAccessManager?

        Thank you
        Jakob

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi,

          Yes you can, but why do you want to make something extra complex ? You already have a state machine. What else are you thinking about ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          B 1 Reply Last reply
          0
          • B Offline
            B Offline
            brunjak
            wrote on last edited by
            #5

            Hi,
            i'm not very used in doing cpp application. I did some C-Project using MicroC/OS-II. Always close to the hardware. It's also my first project with QT. For that reason i don't know which class will fit best for my application.

            But in this case i will try it with QtNetworkManager.

            Thank you
            Jakob

            1 Reply Last reply
            0
            • SGaistS SGaist

              Hi,

              Yes you can, but why do you want to make something extra complex ? You already have a state machine. What else are you thinking about ?

              B Offline
              B Offline
              brunjak
              wrote on last edited by
              #6

              @SGaist

              Hi,
              I'm trying to download a file from the ftp server. This is my code:

              void downloader::doDownload()
              {
                  manager = new QNetworkAccessManager(this);
              
                  connect(manager, SIGNAL(finished(QNetworkReply*)),
                          this, SLOT(replyFinished(QNetworkReply*)));
              
                  url = new QUrl;
                  url->clear();
                  url->setScheme("ftp");
                  url->setUserName("admin");
                  url->setPassword("admin");
                  url->setHost("192.168.0.20");
                  url->setPath("/exp00ded.csv");
              
                  manager->get(QNetworkRequest(QUrl(*url)));
              
              }
              

              I get the following error from ftp server:

              "Error while downloading ftp://admin:admin@192.168.0.20/exp00ded.csv: Command not implemented."

              By checking with wireshark I can see the following commands:

              Response: 220 lwIP FTP Server ready.
              Request: USER admin
              Response: 331 User name okay, need password.
              Request: PASS admin
              Response: 230 User logged in, proceed.
              Request: HELP
              Response: 502 Command not implemented.
              Request QUIT
              Respoonse: 221 Goodbye.

              QUESTION:
              How can I send custom requests like QNetworkAccessManager::sendCustomRequest? But this feature is currently available for HTTP(S) only.

              Thank you
              Jakob

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #7

                What port is your ftp server listening on ?

                By the way, you should not allocate QUrl on the heap, you currently have a memory leak.

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                B 1 Reply Last reply
                0
                • SGaistS SGaist

                  What port is your ftp server listening on ?

                  By the way, you should not allocate QUrl on the heap, you currently have a memory leak.

                  B Offline
                  B Offline
                  brunjak
                  wrote on last edited by
                  #8

                  @SGaist
                  Thank you for your response. I realy appreciate that.

                  The servers control channel is listening at port 21. The Servers data channel port is unknown until data are requested. Then the servers tells which port the client should use for data connection.

                  Thank you
                  Jakob

                  1 Reply Last reply
                  0
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    Then shouldn't you set the port to 21 in your url ?

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    B 1 Reply Last reply
                    0
                    • SGaistS SGaist

                      Then shouldn't you set the port to 21 in your url ?

                      B Offline
                      B Offline
                      brunjak
                      wrote on last edited by
                      #10

                      @SGaist
                      ... i will tray it. In my opinion it won't solve the problem. In the wireshark log I could see that the port is 21. By defining url->setSheme to "ftp" the port is defined because ftp uses Port 21 as control channel. You can also see that a communication could be established. Otherwise USER and PASS would not be accepted. I think the problem is, that the manager->get(QNetworkRequest(QUrl(*url))) follows a fixed structure.

                      1. USER
                      2. PASS
                      3. HELP (To get all the possible commands which are implemted at the server side. If HELP is not implemented the connection will be closed. According to rfc959 (chapter 5.1) the minimum implementation does not demand HELP.

                      I konw the command sequence to download the file "exp00ded.csv. But i don't know how to send single commands.

                      Thank you.
                      Jakob

                      1 Reply Last reply
                      0
                      • B Offline
                        B Offline
                        brunjak
                        wrote on last edited by
                        #11

                        Hi,
                        Also by setting url->port to 21 it beaves the same way like without setting the port to 21. Any other idea?

                        Thank you
                        Jakob

                        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