-
Implementation
- protected: void incomingConnection(int socketDescriptor);
-
void FortuneServer::incomingConnection(int socketDescriptor)
- FortuneThread *thread = new FortuneThread(socketDescriptor, fortune, this);
- connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
- thread->start();
-
void FortuneThread::run()
- QTcpSocket tcpSocket;
- if (!tcpSocket.setSocketDescriptor(socketDescriptor)) { emit error(tcpSocket.error()); return;}
-
Подготовка данных
- QByteArray block;
- QDataStream out(&block, QIODevice::WriteOnly);
- out <<
- tcpSocket.write(block);
- tcpSocket.disconnectFromHost();
- tcpSocket.waitForDisconnected()