我能打开多个客户端连接到服务器,并且返回
可是每个客户端只能连接一次!!!我很奇怪~为啥只能连接一次???
下面是我服务器主要代码:
QtcpServer:
- C/C++ code
void CServer::incomingConnection( int socketDescriptor ){ CServerThread *pThread = new CServerThread(socketDescriptor, this); connect(pThread, SIGNAL(finished()), this, SLOT(deleteLater())); pThread->start();}
QThread
- C/C++ code
void CServerThread::run(){ m_pClientConnection = new QTcpSocket(this); if (!m_pClientConnection->setSocketDescriptor(m_nSocketDescriptor)) { return; } connect(m_pClientConnection, SIGNAL(readyRead()), this, SLOT(slotGetXmlFromClient()), Qt::QueuedConnection); connect(m_pClientConnection, SIGNAL(disconnected()), this, SLOT(deleteLater())); this->exec();}
我知道QTcpServer有2种接收信号的方式,一个是newConnection()一个就是重载incomingConnection ( int socketDescriptor ),我现在用的是后者,问题就是第二次发送消息,就接不到了!~
肯请大牛指点迷津,谢谢
------解决方案--------------------
你的程序只执行了一次m_pTcpSocket->connectToHost("192.168.6.1", 8764);
哪来的第二次连接?