为什么我无法使用 telnet 客户端连接到在我的本地主机上运行的服务器?
我正在使用 windows-7 并且在控制面板中打开了 telnet 客户端。
请建议如何使它工作?
#define SERVER_PORT 5000
tcp server 是在 tcpserver 对象中创建的:---
tcpserverobject::tcpserverobject(QObject *parent) :
QObject(parent), tcpServer(0)
{
tcpServer = new QTcpServer;
connect(tcpServer, SIGNAL(newConnection()), this, SLOT(on_newConnection()));
}
// tcpserver 的公共槽 - 线程
void tcpserverobject::dowork()
{
if (!tcpServer->listen(QHostAddress::LocalHost, SERVER_PORT )) {
qDebug() << "\n returning from server listning error .. !!! ";
return;
}
qDebug() << "\n server listning";
//while(1)
while(!m_bQuit)
{
}
}
服务器新连接代码:---
void tcpserverobject::on_newConnection()
{
QByteArray block;
block.append(" \n Hello from server .. !!!") ;
QTcpSocket *clientConnection = tcpServer->nextPendingConnection();
connect(clientConnection, SIGNAL(disconnected()),
clientConnection, SLOT(deleteLater()));
// Create new thread for this .. client request ..!!
qDebug() << "\n New connection request ..!!!";
qDebug() << "\n New client from:" << clientConnection->peerAddress().toString();
clientConnection->write(block);
clientConnection->flush();
clientConnection->disconnectFromHost();
qDebug() << "\n New connection request closed ..!!!";
}
现在我在 telnet 中输入命令:----
C:\Users\Admin> telnet
Welcome to Microsoft Telnet Client
Escape Character is 'CTRL+]'
Microsoft Telnet> open localhost 5000
Connecting To localhost...
我可以让我的服务器进入侦听模式,因为打印了以下语句:-
qDebug() << "\n server listning";
但是为什么 telnet 客户端无法连接到在 localhost & PORT = 5000 上运行的服务器?