Work with QTcpSocket
QTcpSocket works asynchronously and emits signals to report status changes and errors, just like QNetworkAccessManager.
Similar Mind Maps
Outline


…
bool QTcpServer::waitForNewConnection(int msec, bool *timedOut)
QTcpServerPrivate::readNotification()
QTcpServer::incomingConnection(int socketDescriptor)
QTcpSocket *socket = new QTcpSocket(this);

socket->setSocketDescriptor(socketDescriptor);
d_func()->pendingConnections.append(socket);

emit newConnection()

constructor myTcpServer::myTcpServer
connect(myTcpServer, SIGNAL(newConnection()), myTcpServer, SLOT(connectionProcess()));
void myTcpServer::connectionProcess()
QTcpSocket *clientConnection = myTcpServer->nextPendingConnection();
connect(clientConnection, SIGNAL(disconnected()), clientConnection, SLOT(deleteLater()));

clientConnection->read(…);
clientConnection->write(…);
clientConnection->disconnectFromHost();


void myTcpServer::incomingConnection(int socketDescriptor)
1. Обработка соединения
1.1. QTcpSocket tcpSocket;
1.2. tcpSocket.setSocketDescriptor(socketDescriptor)
1.3. clientConnection->read(…);
1.4. clientConnection->write(…);
1.5. clientConnection->disconnectFromHost();
1.6. tcpSocket.waitForDisconnected();

2. Создаем новый поток