Results 1 to 4 of 4

Thread: Telnet connection does not establish...

  1. #1
    Join Date
    Dec 2008
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Telnet connection does not establish...

    Hello,

    I am trying to establish a telnet connection in a console application. I have the following code:

    Qt Code:
    1. QTcpSocket *QTcpSocketMine = new QTcpSocket();
    2. QTcpSocketMine->connectToHost("192.168.1.1", 23);
    3. if (QTcpSocketMine->isOpen())
    4. {
    5. qDebug() << "QTcpSocketMine->isOpen() == true";
    6. } else
    7. {
    8. qDebug() << "QTcpSocketMine->isOpen() == false";
    9. }
    10.  
    11. if (QTcpSocketMine->isValid())
    12. {
    13. qDebug() << "QTcpSocketMine->isValid() == true";
    14. } else
    15. {
    16. qDebug() << "QTcpSocketMine->isValid() == false";
    17. }
    18.  
    19. if (QTcpSocketMine->waitForConnected(3000))
    20. {
    21. qDebug() << "connection established.";
    22. } else
    23. {
    24. QString QStringErrorString = QTcpSocketMine->errorString();
    25. qDebug() << QStringErrorString;
    26. }
    To copy to clipboard, switch view to plain text mode 

    If I set the parameter of QTcpSocketMine->waitForConnected to -1 the program does not exit any more. If i read the error message with

    QString QStringErrorString = QTcpSocketMine->errorString();
    qDebug() << QStringErrorString;

    it prints Socket operation timed out. If I open putty and connect to 192.168.1.1:23 it immediately works. Same with the Windows telnet client. What could that be?

    Another problem is, that the signals and slots do not work.
    I define

    connect(QTcpSocketMine, SIGNAL(connected()), this, SLOT(connectionComplete()));
    connect(QTcpSocketMine, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(errorOccured(QAbstractSocket::SocketError)));
    connect(QTcpSocketMine, SIGNAL(hostFound()), this, SLOT(hostFoundComplete()));
    connect(QTcpSocketMine, SIGNAL(stateChanged(QAbstractSocket::SocketState)) , this, SLOT(handleStateChanged(QAbstractSocket::SocketSta te)));

    in the cpp and my whole h looks like that:

    Qt Code:
    1. #ifndef QMYPROCESS_H
    2. #include <QProcess>
    3. #include <QDebug>
    4. #include <QTcpSocket>
    5.  
    6. class QMyProcess: public QProcess
    7. {
    8. Q_OBJECT;
    9.  
    10. public:
    11. QMyProcess();
    12.  
    13. public slots:
    14. void connectionComplete();
    15. void errorOccured(QAbstractSocket::SocketError socketError);
    16. void hostFoundComplete();
    17. void handleStateChanged(QAbstractSocket::SocketState socketState);
    18. };
    19.  
    20. #endif // QMYPROCESS_H
    To copy to clipboard, switch view to plain text mode 
    Do I miss something?

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Telnet connection does not establish...

    Just curious, is it a wireless connection? I've had some problems with QTcpSocket and wireless connection lately.
    J-P Nurmi

  3. #3
    Join Date
    Jun 2011
    Posts
    26
    Thanks
    3
    Thanked 3 Times in 3 Posts

    Default Re: Telnet connection does not establish...

    Could you solve it? I want to do exactly that. Establish a telnet connection and send commands/receive data.

    Regards,

    -E

  4. #4
    Join Date
    Dec 2008
    Location
    France
    Posts
    93
    Thanked 23 Times in 22 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default Re: Telnet connection does not establish...

    Not a solution to your problem, but have you look to http://doc.qt.nokia.com/solutions/4/...t.html#details.
    I used it one year ago and it worked fine for sending command and receiving responses thought telnet (I was watching system log in real time from an embedded device thought it).
    Maybe it will help you to save some time.

Similar Threads

  1. SQL connection closure problem.
    By cbarmpar in forum Qt Programming
    Replies: 1
    Last Post: 8th September 2008, 08:42
  2. QSQLITE | unable to establish connection
    By suresh in forum Newbie
    Replies: 4
    Last Post: 1st July 2008, 11:17
  3. Client/Server Error: BadIDChoice
    By 3nc31 in forum Qt Programming
    Replies: 5
    Last Post: 27th November 2007, 10:22
  4. How do I keep the client connection open ?
    By probine in forum Newbie
    Replies: 2
    Last Post: 25th March 2006, 19:06

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.