# include <QTcpSocket>
# include <iostream>
# include "client.h"
# include "server.h"
using namespace std;
Client
:: Client(int socketDescriptor, Server
*server,
QObject *parent
) : QThread(parent
){
this->socketDescriptor = socketDescriptor;
this->server = server;
connect(this, SIGNAL(finished()), this, SLOT(finished()));
}
void Client :: run()
{
cout << "void Client :: run()\n";
if(!tcpSocket->setSocketDescriptor(socketDescriptor))
{
cout << "Error - tcpSocket descriptor\n";
return;
}
connect(tcpSocket, SIGNAL(readyRead()), this, SLOT(readData()));
connect(tcpSocket, SIGNAL(disconnected()), this, SLOT(clientDisconnected()));
exec();
}
void Client :: readData()
{
cout << "void Client :: readData()\n";
server->addClient("12345", this);
}
void Client :: clientDisconnected()
{
cout << "void Client :: clientDisconnected()\n";
}
void Client :: finished()
{
cout << "The thread has finished\n";
}
# include <QTcpSocket>
# include <iostream>
# include "client.h"
# include "server.h"
using namespace std;
Client :: Client(int socketDescriptor, Server *server, QObject *parent) : QThread(parent)
{
this->socketDescriptor = socketDescriptor;
this->server = server;
chattingWith = new QString();
connect(this, SIGNAL(finished()), this, SLOT(finished()));
}
void Client :: run()
{
cout << "void Client :: run()\n";
tcpSocket = new QTcpSocket();
if(!tcpSocket->setSocketDescriptor(socketDescriptor))
{
cout << "Error - tcpSocket descriptor\n";
return;
}
connect(tcpSocket, SIGNAL(readyRead()), this, SLOT(readData()));
connect(tcpSocket, SIGNAL(disconnected()), this, SLOT(clientDisconnected()));
exec();
}
void Client :: readData()
{
cout << "void Client :: readData()\n";
server->addClient("12345", this);
}
void Client :: clientDisconnected()
{
cout << "void Client :: clientDisconnected()\n";
}
void Client :: finished()
{
cout << "The thread has finished\n";
}
To copy to clipboard, switch view to plain text mode
Bookmarks