void ClientThread::run() { qDebug() << socketDescriptor << " Starting thread"; socket = new QTcpSocket(); if ( !socket->setSocketDescriptor(this->socketDescriptor) ) { emit error(socket->error()); return; } qDebug() << socketDescriptor << " Waiting for authentication"; user = new User(socketDescriptor, "bob", QHostAddress::LocalHost); socket->write("please enter your login:password\n"); if (authenticateClient()) { qDebug() << socketDescriptor << " Client authenticated"; socket->write("authenticated\n"); socket->write(QString(user->accessLevel).toLocal8Bit()); emit clientAuthenticated(user); } else { socket->write("authentication failed\n"); qDebug() << socketDescriptor << " Authentication failed"; QTimer::singleShot(1, socket, SLOT(disconnectFromHostImplementation())); } connect(socket, SIGNAL(readyRead()), this, SLOT(readyRead()), Qt::DirectConnection); connect(socket, SIGNAL(disconnected()), this, SLOT(disconnected()), Qt::DirectConnection); exec(); }
void Server::incomingConnection(int id) { QThread* thread = new QThread(); ServerSocket* socket = new ServerSocket(id); socket->moveToThread(thread); thread->start(); connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater())); connect(socket, SIGNAL(logGenerated(QString)), this, SLOT(on_socket_logGenerated(QString))); connect(socket, SIGNAL(imageRead(QByteArray)), this, SLOT(on_socket_imageRead(QByteArray))); connect(this, SIGNAL(serverTerminated()), socket, SLOT(disconnectFromHostImplementation())); connect(this, SIGNAL(serverTerminated()), socket, SLOT(abortConnection())); connect(socket, SIGNAL(disconnected()), thread, SLOT(quit())); //Seems risky }
void DhQAbstractSocket::DvhdisconnectFromHostImplementation() { return disconnectFromHostImplementation(); }