0

I have attached the code I am working on. As you can see I am establishing connection with the server and I am waiting for the response of it.

I am executing the command lb which lists me a set of commands. I have successfully established connection with the server, but I do not get the result for the command that I execute.

What I am trying to do is, I am establishing a telnet connection between my server and my code. I am trying to execute the commands indirectly from my code and process the output result obtained from the server.

char buffer[1024] = {0};
socket = new QTcpSocket(this);
QString hostaddress = "101.7324.156.19";
socket->connectToHost(hostaddress,23,QIODevice::ReadWrite);

if(socket->waitForConnected(3000))
{
    qDebug() << "connected";

    socket->write("lb");
    socket->waitForBytesWritten(1000);
    socket->waitForReadyRead(1000);

    qDebug() << "reading" << socket->bytesAvailable();

    socket->read(buffer,socket->bytesAvailable());
    qDebug() << buffer << endl;

    socket->close();
}
else
{
    qDebug() << "not connected";
}
Cœur
  • 37,241
  • 25
  • 195
  • 267
sankar
  • 347
  • 3
  • 4
  • 15
  • 1
    I think you have to add \n to the end of your command when writing to a telnet server. – thuga Aug 01 '13 at 10:54
  • @thuga: I have included the \n as you had told. But the output is the same. The output i am getting now is, "connected" and "reading 25" and some junk values for buffer. – sankar Aug 01 '13 at 10:57
  • How much do you know about telnet? When you try to establish a telnet connection, you must define some options through DO/WILL/DONT/WONT messages. These messages will usually appear as junk as they are values between 0 and 255. – thuga Aug 01 '13 at 11:34
  • I am not proficient in using telnet. I am a beginner on both the QTcp socket and telnet... can you please provide me with links where i can find information about the options when i establish the connection – sankar Aug 01 '13 at 11:40
  • You should read about [RFC 854](http://tools.ietf.org/html/rfc854) if you're going to use telnet. – thuga Aug 01 '13 at 11:47

0 Answers0