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. [SOLVED] QTcpServer::listen randomly fails
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] QTcpServer::listen randomly fails

Scheduled Pinned Locked Moved General and Desktop
10 Posts 3 Posters 4.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.
  • T Offline
    T Offline
    t3685
    wrote on last edited by t3685
    #1

    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
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

      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
      2
      • T Offline
        T Offline
        t3685
        wrote on last edited by
        #3

        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
        0
        • C Offline
          C Offline
          ckakman
          wrote on last edited by
          #4

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

          1 Reply Last reply
          0
          • T Offline
            T Offline
            t3685
            wrote on last edited by
            #5

            It seems I have been blind :-)

            1 Reply Last reply
            0
            • dheerendraD Offline
              dheerendraD Offline
              dheerendra
              Qt Champions 2022
              wrote on last edited by
              #6

              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
              2
              • T Offline
                T Offline
                t3685
                wrote on last edited by
                #7

                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
                0
                • dheerendraD Offline
                  dheerendraD Offline
                  dheerendra
                  Qt Champions 2022
                  wrote on last edited by
                  #8

                  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
                  1
                  • T Offline
                    T Offline
                    t3685
                    wrote on last edited by
                    #9

                    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
                    0
                    • T Offline
                      T Offline
                      t3685
                      wrote on last edited by
                      #10

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

                      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