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 won't call "incomingConnection" in Windows applications
Forum Updated to NodeBB v4.3 + New Features

[Solved] QTcpServer won't call "incomingConnection" in Windows applications

Scheduled Pinned Locked Moved General and Desktop
14 Posts 3 Posters 7.0k 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.
  • C Offline
    C Offline
    Crocket_63
    wrote on last edited by
    #1

    Hi there!

    I successfully developped a litle TCP server application, by reimplementing "incomingConnection" method, which creates a new thread passing it the socket descriptor.

    Well this is done just as the documentation says, and just has in the threaded fortune server example for QT, and it works like a charm.

    Ok so why this help message?:
    The thing is that I worked in a linux environment, and now try to port that under windows.
    Compiled like a charm, that was really nice to see... but:

    It just does not work: the incomingConnection is never called when a client connects unlike what happens in my linux compiled version !?!?

    Any advices?

    Thanks!

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

      It should work. Can you check and port# and IP address used for connecting ? Can you whether connection is really made ? Can you check which IP address and port# server is binding ?

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

      1 Reply Last reply
      0
      • C Offline
        C Offline
        Crocket_63
        wrote on last edited by
        #3

        Well to add some details:
        TCPServer listening is launched this way:
        if (!this->listen(QHostAddress::Any, listeningPort))

        After that it reports:
        Server isListening: true
        Server listening port: 21005
        Server listening ip: QHostAddress( "0.0.0.0" )
        Server max pending=: 30

        My client program is not rejected when connecting so seems that the tcp low level is just waiting to be accepted.

        Furthermore, I tried to add in the server:
        connect(this, SIGNAL newConnection, this, SLOT thereIsnewConnection);

        And when the client connects, I have in fact a call in my thereIsnewConnection slot. But still no call to "incomingConnection" :(

        And as I need to send a socket descriptor to a thread I really need that call as documentation states the QTCPsocket object should not be passed to a thread.

        Thanks for your help!

        ps:This is using QT 5.3.1 on windows seven SP1 64bits

        1 Reply Last reply
        0
        • C Offline
          C Offline
          Crocket_63
          wrote on last edited by
          #4

          Am I the only one to have that problem?

          For information, same code was working under Ubuntu using Qt 5.2.1

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

            what is happening at the client side ? You can use the following two signals

            1. error()
            2. connected()

            Connect these two slots at client side to some function. Error function should give what is the error if not able to connect.

            My suspect is that IP address passed from client is some how not correct.

            Do you have client and server on the same system ?
            Are you running client & servers running in different system ?

            If they are running different system, just check IP address of server you used to connect.

            If you are not able to verify with any of the above, then we can check the network packets with wireshark and see whatz is happening at network level. This is our last and final step. Hope we don't reach this.

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

            1 Reply Last reply
            0
            • C Offline
              C Offline
              Crocket_63
              wrote on last edited by
              #6

              Test is done using 127.0.0.1 on the same system.

              On client side it's pretty simple:
              if (! tcpSocket->waitForConnected() ){
              cerr << "could not find host" << endl;
              exit(1);
              }

              cout << "connect state " << tcpSocket->state();
              

              Connect state shows 3, which is state "Connected" I believe.

              So yes, client really seems to get connected, and as I stated before, the server signal "newConnection" is emitted when client is run...

              Really strange.... Just seems that the server mechanism to call "incomingConnection " is not working on my windows system... Any change has been done from 5.2.1 to 5.3.1??

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

                client really seems to get connected, and as I stated before, the server signal >“newConnection” is emitted when client is run

                What do you mean here ? newConnection signal is emitted at server when client is run ? Do you mean to say signal is not emitted when client is connecting but it emits later ?

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

                1 Reply Last reply
                0
                • C Offline
                  C Offline
                  Crocket_63
                  wrote on last edited by
                  #8

                  Yes exactly, the server signal is emitted as soon as the client connects.

                  But I used that signal just to check if server was seing the connection, as I intially just wanted to get the incomingConnection call mechanism to work, exactly as in the threaded fortune server Qt example.

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

                    Since newConnection is happening it means that incomingConnection(..) is surely working. Internally base implementation calls incommingConnection(..) when ever the connection request arrives.

                    Last thing I would like to see is the your class declaration where incomingConnection(...) is defined and it's corresponding implementation. You can paste the code here.

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

                    1 Reply Last reply
                    0
                    • C Offline
                      C Offline
                      Crocket_63
                      wrote on last edited by
                      #10

                      oh dear oh dear...

                      I think I got it....

                      In the Qt example it's declared

                      protected:
                      void incomingConnection(int socketDescriptor);

                      But actually it's a qintptr socketDescriptor ...

                      So I guess it was recognised as a qintptr under my 32bit linux... But a different method when compiled on my windows 64 system...

                      I can't test it right now but I'm pretty sure that's the issue...

                      I'll tell you tomorrow :)

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

                        Hi,

                        Are you by any chance looking at a Qt 4.8 example while using Qt 5 ?

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

                        1 Reply Last reply
                        0
                        • C Offline
                          C Offline
                          Crocket_63
                          wrote on last edited by
                          #12

                          Yes seems I got trapped by the Qt version when looking at the example...

                          That was a nice trap to get into :p

                          Still didn't test with the new definition but pretty confident that was my issue :p

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

                            Which example was it ?

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

                            1 Reply Last reply
                            0
                            • C Offline
                              C Offline
                              Crocket_63
                              wrote on last edited by
                              #14

                              I first looked at the correct examples, but probably came back to the wrong one with a google search pointing to an old example version :(

                              Here was the old one declared as an "int".
                              http://qt-project.org/doc/qt-4.8/network-threadedfortuneserver.html

                              I recompiled this for 64 bit just changing int into qintptr and: now it works like a charm!!!

                              Thanks for the help, will be more carefull with the new qtype declarations :p

                              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