Im having trouble with my telnet connection by TCP where i need to enter the initials twice as the server needs this (not my server) but then when i have the initials entered once and are about to type them in the second time it seems like im getting thrown off
this is the code when i push a button it needs to connect by TCP to a ip entered in the GUI
IMPORTANT when i try and connect to the server with putty it works fine
void MainWindow::on_reboot_clicked()
{
QString hostName
= ui
->hostName
->text
();
int port = ui->Port->text().toInt();
//connection
socket
->connectToHost
(hostName, port,
QIODevice::ReadWrite);
if(socket->waitForConnected(300)){//if succesfull connection run this
qDebug() << "connected";
//sending initials first time
socket->write("admin\r\n");
socket->waitForReadyRead(10);
qDebug() << "reading first" << socket->readAll();
socket->waitForBytesWritten(10);
//socket->waitForReadyRead(10);
socket->write("Admin1\r\n");
socket->waitForReadyRead(10);
socket->waitForBytesWritten(10);
//socket->waitForReadyRead(10);
qDebug() << "reading second" << socket->readAll();
//sending initials second time
socket->write("admin\r\n");
socket->waitForReadyRead(10);
socket->waitForBytesWritten(10);
//socket->waitForReadyRead(10);
qDebug() << "reading third" << socket->readAll();
socket->write("Admin1\r\n");
socket->waitForReadyRead(10);
socket->waitForBytesWritten(10);
//socket->waitForReadyRead(10);
qDebug() << "reading fourth" << socket->readAll();
//reboot command
socket->write("reboot\r\n");
socket->waitForBytesWritten(2000); // waiting the 2 seconds for the reboot command to take effect
qDebug() << "done";
//closing connection
socket->close();
}
else {//if the program couldn't connect the program will output this in debug terminal
qDebug() << "not connected";
}
}
void MainWindow::on_reboot_clicked()
{
QString hostName = ui->hostName->text();
int port = ui->Port->text().toInt();
socket = new QTcpSocket(this);
//connection
socket->connectToHost(hostName, port, QIODevice::ReadWrite);
if(socket->waitForConnected(300)){//if succesfull connection run this
qDebug() << "connected";
//sending initials first time
socket->write("admin\r\n");
socket->waitForReadyRead(10);
qDebug() << "reading first" << socket->readAll();
socket->waitForBytesWritten(10);
//socket->waitForReadyRead(10);
socket->write("Admin1\r\n");
socket->waitForReadyRead(10);
socket->waitForBytesWritten(10);
//socket->waitForReadyRead(10);
qDebug() << "reading second" << socket->readAll();
//sending initials second time
socket->write("admin\r\n");
socket->waitForReadyRead(10);
socket->waitForBytesWritten(10);
//socket->waitForReadyRead(10);
qDebug() << "reading third" << socket->readAll();
socket->write("Admin1\r\n");
socket->waitForReadyRead(10);
socket->waitForBytesWritten(10);
//socket->waitForReadyRead(10);
qDebug() << "reading fourth" << socket->readAll();
//reboot command
socket->write("reboot\r\n");
socket->waitForBytesWritten(2000); // waiting the 2 seconds for the reboot command to take effect
qDebug() << "done";
//closing connection
socket->close();
}
else {//if the program couldn't connect the program will output this in debug terminal
qDebug() << "not connected";
}
}
To copy to clipboard, switch view to plain text mode
Here is what i am getting on the output terminal
connected
reading first "\xFF\xFB\x01"
reading second "\xFF\xFB\x03"
QAbstractSocket::waitForBytesWritten() is not allowed in UnconnectedState
reading third ""
QAbstractSocket::waitForBytesWritten() is not allowed in UnconnectedState
reading fourth ""
QAbstractSocket::waitForBytesWritten() is not allowed in UnconnectedState
done
and i just can't seem to figure out what is wrong
Bookmarks