im trying to make an app able to login to telnet server where it needs to type in the login details twice and im getting thrown off the connection "i think" whenever i need to type the initials the second time im here is my code im running when pressing my button

void MainWindow:n_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";

}
}

and im getting this in the 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 when looking at wireshark i can see 3 packets being sent