Work with QTcpSocket

undefined
undefined
Work with QTcpSocket
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();
Reimplement incomingConnection(int socketDescriptor)
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.
Создаем новый поток
bool QTcpServer::listen(const QHostAddress &address, quint16 port)
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()
2