Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    [SOLVED] QTcpServer::listen randomly fails

    General and Desktop
    3
    10
    3430
    Loading More Posts
    • 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.
    • T
      t3685 last edited by t3685

      Hi,

      I am looking for some clues why QTcpServer::listen (apparently) randomly fails. I am using Ubuntu 64bit 14.04, Qt5.3.2

      I am listening on localhost:50000. From the command line I can see that this address is free, however sometimes QTcpServer::listen just fails.

      Has anyone ever encountered this? Or can anyone point me in the right direction?

      Greetings,

      t3685

      1 Reply Last reply Reply Quote 0
      • dheerendra
        dheerendra Qt Champions 2022 last edited by

        What is the error it throws ? Are u restarting your server frequently ?

        Dheerendra
        @Community Service
        Certified Qt Specialist
        http://www.pthinks.com

        1 Reply Last reply Reply Quote 2
        • T
          t3685 last edited by

          Hi,

          The server is started right after boot up, I check for the return value of listen and see that it is false. I don't know see any other errors, unless I missed something. Is there a way to get more detailed information as to why it would fail?

          1 Reply Last reply Reply Quote 0
          • C
            ckakman last edited by

            http://doc.qt.io/qt-5/qtcpserver.html#errorString

            1 Reply Last reply Reply Quote 0
            • T
              t3685 last edited by

              It seems I have been blind :-)

              1 Reply Last reply Reply Quote 0
              • dheerendra
                dheerendra Qt Champions 2022 last edited by

                when the bind fails, just call QTCPServer.errorString(...). This will return the last error occurred. I'm suspecting either your interfaces are not up when you give bind or port you are binding is already used by some other process. errorString() should clear the dust.

                Dheerendra
                @Community Service
                Certified Qt Specialist
                http://www.pthinks.com

                1 Reply Last reply Reply Quote 2
                • T
                  t3685 last edited by

                  Hi,

                  Sorry for re-opening this. I am getting QAbstractSocket::AddressInUseError at bootup. Subsequent attempts to are successful. Has anyone come across something like this before?

                  Greetings,

                  t3685

                  1 Reply Last reply Reply Quote 0
                  • dheerendra
                    dheerendra Qt Champions 2022 last edited by

                    Port you are specifying might have used by other process before your program binds or your program itself may be doing the bind twice within short interval. I suspect the first issue.

                    Dheerendra
                    @Community Service
                    Certified Qt Specialist
                    http://www.pthinks.com

                    1 Reply Last reply Reply Quote 1
                    • T
                      t3685 last edited by

                      I have tried using different ports, but the same result. I will check whether my server is not calling listen twice.

                      1 Reply Last reply Reply Quote 0
                      • T
                        t3685 last edited by

                        I fixed the problem by switching for using a QApplication object in my main function to a QCoreApplication.

                        1 Reply Last reply Reply Quote 0
                        • First post
                          Last post