PDA

View Full Version : Telnet connection does not establish...



gentlesea
23rd December 2008, 10:47
Hello,

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


QTcpSocket *QTcpSocketMine = new QTcpSocket();
QTcpSocketMine->connectToHost("192.168.1.1", 23);
if (QTcpSocketMine->isOpen())
{
qDebug() << "QTcpSocketMine->isOpen() == true";
} else
{
qDebug() << "QTcpSocketMine->isOpen() == false";
}

if (QTcpSocketMine->isValid())
{
qDebug() << "QTcpSocketMine->isValid() == true";
} else
{
qDebug() << "QTcpSocketMine->isValid() == false";
}

if (QTcpSocketMine->waitForConnected(3000))
{
qDebug() << "connection established.";
} else
{
QString QStringErrorString = QTcpSocketMine->errorString();
qDebug() << QStringErrorString;
}

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:


#ifndef QMYPROCESS_H
#include <QProcess>
#include <QDebug>
#include <QTcpSocket>

class QMyProcess: public QProcess
{
Q_OBJECT;

public:
QMyProcess();

public slots:
void connectionComplete();
void errorOccured(QAbstractSocket::SocketError socketError);
void hostFoundComplete();
void handleStateChanged(QAbstractSocket::SocketState socketState);
};

#endif // QMYPROCESS_H

Do I miss something?

jpn
16th January 2009, 20:15
Just curious, is it a wireless connection? I've had some problems with QTcpSocket and wireless connection lately.

Ethan
11th July 2011, 09:27
Could you solve it? I want to do exactly that. Establish a telnet connection and send commands/receive data.

Regards,

-E

nix
11th July 2011, 09:54
Not a solution to your problem, but have you look to http://doc.qt.nokia.com/solutions/4/qttelnet/qttelnet.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.