Results 1 to 7 of 7

Thread: QTCPSocket not connecting

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jul 2006
    Posts
    33
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Windows

    Default QTCPSocket not connecting

    I am running the Fortune Server and Fortune Client examples. Unfortunately, both programs start up fine, but they do not make a TCP socket connection. The server says it is listening, and 'netstat' confirms this. After the client calls 'connectToHost', the socket is supposedly open. Here is the code that I use to confirm that:
    Qt Code:
    1. getFortuneButton->setEnabled(false);
    2. blockSize = 0;
    3. tcpSocket->abort();
    4. tcpSocket->connectToHost(hostLineEdit->text(),
    5. portLineEdit->text().toInt());
    6.  
    7. if (tcpSocket->isOpen ())
    8. statusLabel->setText ("It is open.");
    9. else
    10. statusLabel->setText ("It is NOT open.");
    To copy to clipboard, switch view to plain text mode 

    I even tried to connect the client to another (non-QT) server application I have and the QT client does not make the connection.

    Does anyone know of any problems with the Fortune Server, Fortune Client examples?

    Thanks,
    DP

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTCPSocket not connecting

    Maybe your firewall is blocking it? And do you use a vanilla fortune client/server or did you modify them in any way?

    The test case you have shown won't work. The socket might be "open", but it doesn't mean the connection is active. Remember that connectToHost is an asynchronous call.

  3. #3
    Join Date
    Jul 2006
    Posts
    33
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTCPSocket not connecting

    I can't see how the firewall is blocking since I use TCP connections all the time on my machine and to my laptop on the same network behind the corp firewall.

    I am using the vanilla program except that I added a callback for the connected signal:
    Qt Code:
    1. connect (tcpSocket, SIGNAL(connected ()), this, SLOT(connectionComplete ()));
    2.  
    3. ...
    4.  
    5. void Client::connectionComplete ()
    6. {
    7. statusLabel->setText ("Connection is complete.");
    8. }
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTCPSocket not connecting

    Quote Originally Posted by DPinLV
    I can't see how the firewall is blocking since I use TCP connections all the time on my machine and to my laptop on the same network behind the corp firewall.
    I don't know, it's just a thing to check to identify the problem. Maybe the port is blocked or something like that. Do you use the same machine for the client and the server?

    I am using the vanilla program except that I added a callback for the connected signal:
    Does the vanilla client-server combination work?

    If you run the server, are you able to telnet to the port it is running on?

  5. #5
    Join Date
    Jan 2006
    Posts
    75
    Thanks
    3
    Thanked 5 Times in 4 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QTCPSocket not connecting

    Yes, please try using the Telnet client to connect first to see it is the problem of firewall or not.

  6. #6
    Join Date
    Jul 2006
    Posts
    33
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTCPSocket not connecting

    Quote Originally Posted by wysota
    I don't know, it's just a thing to check to identify the problem. Maybe the port is blocked or something like that.
    Do you use the same machine for the client and the server?
    Does the vanilla client-server combination work?
    Yes, they are on the same machine. This is the plain vanilla client / server, and they do not work. I then added slots to the client for when the connection is done, and I put breakpoints in those methods, but they are never reached:
    Qt Code:
    1. connect (tcpSocket, SIGNAL(connected ()), this, SLOT(connectionComplete ()));
    2. connect (tcpSocket, SIGNAL(hostFound ()), this, SLOT(hostFoundComplete ()) );
    To copy to clipboard, switch view to plain text mode 

    Next, I added a button to get the status of the client connection and supposedly the connection is in the "connected state". I even looked at netstat and the connection is established, but no data is exchanged.
    Qt Code:
    1. connect (statusButton, SIGNAL(clicked()), this, SLOT(getSocketState ()) );
    2. ...
    3. void Client::getSocketState ()
    4. {
    5. switch (tcpSocket->state ())
    6. {
    7. case QAbstractSocket::UnconnectedState:
    8. status2Label->setText (tr("unconnected state"));
    9. break;
    10. case QAbstractSocket::HostLookupState:
    11. status2Label->setText (tr("host lookup state"));
    12. break;
    13. case QAbstractSocket::ConnectingState:
    14. status2Label->setText (tr("connecting state"));
    15. break;
    16. case QAbstractSocket::ConnectedState:
    17. status2Label->setText (tr("connected state"));
    18. break;
    19. case QAbstractSocket::BoundState:
    20. status2Label->setText (tr("bound state"));
    21. break;
    22. case QAbstractSocket::ClosingState:
    23. status2Label->setText (tr("Closing state"));
    24. break;
    25. case QAbstractSocket::ListeningState:
    26. status2Label->setText (tr("Listening state"));
    27. break;
    28. default:
    29. status2Label->setText (tr("Unknown state"));
    30. break;
    31. }
    32. }
    To copy to clipboard, switch view to plain text mode 

    Quote Originally Posted by wysota
    If you run the server, are you able to telnet to the port it is running on?
    When I telnet to the server my server breakpoints are not hit, but if I close the server, my telnet window sees the closure. It is as though the connection is never 'accepted'?

    Thanks.
    DP

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTCPSocket not connecting

    Your computer seems to be blocking the connection somehow... Do other networking examples work? Also please try to start a fake server on the same port the fortunecookie server uses (for example by using netcat) and then try to connect to it using telnet and send some lines of text to it.

  8. The following user says thank you to wysota for this useful post:

    DPinLV (25th August 2006)

Similar Threads

  1. Connecting signals & slots across different threads
    By jyoti kumar in forum Qt Programming
    Replies: 4
    Last Post: 16th May 2006, 12:40
  2. QSocket: connecting but not connected
    By olberg in forum Qt Programming
    Replies: 3
    Last Post: 8th May 2006, 10:26
  3. Error connecting to MySQL
    By probine in forum Qt Programming
    Replies: 20
    Last Post: 23rd February 2006, 23:13
  4. QTcpSocket disconnection problem
    By erdi in forum Qt Programming
    Replies: 4
    Last Post: 19th February 2006, 21:50
  5. Check connecting to Internet
    By gtthang in forum Qt Programming
    Replies: 2
    Last Post: 17th February 2006, 17:13

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.