我正在开发Qt应用程序,以便能够通过telnet登录到服务器。
然后登录到该服务器以向其发送命令,但是我似乎无法登录到该服务器,需要具有两次凭据才能登录。
在我的代码中,我可以看到im能够首先键入我的凭据,但是随后当它想在第二次键入我的凭据时,由于它似乎已断开连接,因此我不被允许使用
。我收到的错误消息是
已连接
先读取“ \ xFF \ xFB \ x01”
读取第二个“ \ xFF \ xFB \ x03”
先阅读“”
在UnconnectedState中不允许使用QAbstractSocket :: waitForBytesWritten()
先阅读“”
在UnconnectedState中不允许使用QAbstractSocket :: waitForBytesWritten()
完成
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");
socket->waitForBytesWritten(10);
socket->waitForReadyRead(10);
qDebug() << "reading first" << socket->readAll();
socket->write("Admin1");
socket->waitForBytesWritten(10);
socket->waitForReadyRead(10);
qDebug() << "reading second" << socket->readAll();
socket->write("admin");
socket->waitForBytesWritten(10);
socket->waitForReadyRead(10);
qDebug() << "reading first" << socket->readAll();
socket->write("Admin1");
socket->waitForBytesWritten(10);
socket->waitForReadyRead(10);
qDebug() << "reading second" << socket->readAll();
//reboot command
socket->write("reboot");
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";
}
}
´´´