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



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



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



  • 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



  • Am I the only one to have that problem?

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



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



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



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



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



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



  • 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 :)


  • Lifetime Qt Champion

    Hi,

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



  • 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


  • Lifetime Qt Champion

    Which example was it ?



  • 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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.