Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. cannot write through opened socket
Qt 6.12 LTS is out! See what's new in the release blog

cannot write through opened socket

Scheduled Pinned Locked Moved Unsolved General and Desktop
13 Posts 2 Posters 2.1k 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.
  • Christian EhrlicherC Offline
    Christian EhrlicherC Offline
    Christian Ehrlicher
    Lifetime Qt Champion
    wrote on last edited by
    #2

    Please take a look at the QTcpServer example. Your code does ... nothing really useful.

    Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
    Visit the Qt Academy at https://academy.qt.io/catalog

    U 1 Reply Last reply
    1
    • Christian EhrlicherC Christian Ehrlicher

      Please take a look at the QTcpServer example. Your code does ... nothing really useful.

      U Offline
      U Offline
      user4592357
      wrote on last edited by user4592357
      #3

      @Christian-Ehrlicher my code is this

      open socket with above code, it returns port number
      port = // get the port number
      
      const QString sPort(Port);
      auto args = QStringList() << sPort << sPort;
      
      if (!QProcess::startDetached(sClientName, args))
      {
          const QString sProgFullPath{ QString::fromLatin1(pDir) +
              QLatin1String("/bin/") + sClientName };
          if (!QProcess::startDetached(sProgFullPath, args))
              return false;
      }
      
      1 Reply Last reply
      0
      • Christian EhrlicherC Offline
        Christian EhrlicherC Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #4

        This code can not work. Follow the QTcpServer examples.

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        U 2 Replies Last reply
        0
        • Christian EhrlicherC Christian Ehrlicher

          This code can not work. Follow the QTcpServer examples.

          U Offline
          U Offline
          user4592357
          wrote on last edited by user4592357
          #5

          @Christian-Ehrlicher this is working code.
          i just tried this
          i created socket with above method, and run telnet localhost $port
          then i sent message to telnet using this port, and it was sent...
          so... is that other app faulty?

          1 Reply Last reply
          0
          • Christian EhrlicherC Christian Ehrlicher

            This code can not work. Follow the QTcpServer examples.

            U Offline
            U Offline
            user4592357
            wrote on last edited by
            #6

            @Christian-Ehrlicher my bad
            the other app expects file descriptors, and i'm providing socket port
            so, how should i work with that app?

            1 Reply Last reply
            0
            • Christian EhrlicherC Offline
              Christian EhrlicherC Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by
              #7

              @user4592357 said in cannot write through opened socket:

              so, how should i work with that app?

              It's your app - how should we know?

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              U 1 Reply Last reply
              0
              • Christian EhrlicherC Christian Ehrlicher

                @user4592357 said in cannot write through opened socket:

                so, how should i work with that app?

                It's your app - how should we know?

                U Offline
                U Offline
                user4592357
                wrote on last edited by
                #8

                @Christian-Ehrlicher i mean it is accepting file descriptors, and i have socket (port).

                how should i convert socket to fd?
                can i do that?

                1 Reply Last reply
                0
                • Christian EhrlicherC Offline
                  Christian EhrlicherC Offline
                  Christian Ehrlicher
                  Lifetime Qt Champion
                  wrote on last edited by
                  #9

                  @user4592357 said in cannot write through opened socket:

                  how should i convert socket to fd?

                  By taking a look at the documentation: https://doc.qt.io/qt-5/qabstractsocket.html#socketDescriptor

                  Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                  Visit the Qt Academy at https://academy.qt.io/catalog

                  U 1 Reply Last reply
                  1
                  • Christian EhrlicherC Christian Ehrlicher

                    @user4592357 said in cannot write through opened socket:

                    how should i convert socket to fd?

                    By taking a look at the documentation: https://doc.qt.io/qt-5/qabstractsocket.html#socketDescriptor

                    U Offline
                    U Offline
                    user4592357
                    wrote on last edited by
                    #10

                    @Christian-Ehrlicher thanks for the link

                    so when i create the child app like this, when main app is closed, child app still exists, as it was started detached:

                    if (!QProcess::startDetached(sClientName, args))
                    {
                        const QString sProgFullPath{ QString::fromLatin1(pDir) +
                            QLatin1String("/bin/") + sClientName };
                        if (!QProcess::startDetached(sProgFullPath, args))
                            return false;
                    }
                    

                    i tried to convert this to using start() instead, but looks it's not equivalent (because now error signal is async?)
                    what's the correct way to nest such call?

                    QProcess p1;
                    p1.start(sClientName, args);
                    connect(&p1, &QProcess::errorOccurred, []
                    {
                        const QString sProgFullPath{ QString::fromLatin1(pDir) +
                            QLatin1String("/bin/") + sClientName };
                    
                         QProcess p2;
                         p2.start(sProgFullPath, args);
                         connect(&p2, &QProcess::errorOccurred, []
                         {
                              // how do i return false from here?
                        });
                    }
                    
                    1 Reply Last reply
                    0
                    • Christian EhrlicherC Offline
                      Christian EhrlicherC Offline
                      Christian Ehrlicher
                      Lifetime Qt Champion
                      wrote on last edited by
                      #11

                      Start both directly instead waiting for the first one.

                      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                      Visit the Qt Academy at https://academy.qt.io/catalog

                      U 2 Replies Last reply
                      0
                      • Christian EhrlicherC Christian Ehrlicher

                        Start both directly instead waiting for the first one.

                        U Offline
                        U Offline
                        user4592357
                        wrote on last edited by
                        #12

                        @Christian-Ehrlicher what if both succeed?

                        1 Reply Last reply
                        0
                        • Christian EhrlicherC Christian Ehrlicher

                          Start both directly instead waiting for the first one.

                          U Offline
                          U Offline
                          user4592357
                          wrote on last edited by
                          #13

                          @Christian-Ehrlicher what about https://doc.qt.io/qt-5/qprocess.html#execute?

                          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
                          • Unsolved