-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserverthread.cpp
More file actions
48 lines (34 loc) · 1005 Bytes
/
serverthread.cpp
File metadata and controls
48 lines (34 loc) · 1005 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include "serverthread.h"
serverThread::serverThread(int socketDescriptor, QObject *parent) :
QThread(parent), socketDescriptor(socketDescriptor)
{
}
serverThread::~serverThread()
{
socket->close();
}
void serverThread::run()
{
socket = new MySocket(socketDescriptor, 0);
if (!socket->setSocketDescriptor(socketDescriptor))
return ;
connect(socket, &MySocket::disconnected, this, &serverThread::disconnectToHost);
connect(socket, SIGNAL(revData(QString, QByteArray)), this, SLOT(recvData(QString, QByteArray)));
connect(this, SIGNAL(sendDat(QByteArray, int)), socket, SLOT(sendMsg(QByteArray, int)));
exec();
}
void serverThread::sendData(QByteArray data, int id)
{
if (data == "")
return ;
emit sendDat(data,id);
}
void serverThread::recvData(QString peerAddr, QByteArray data)
{
emit revData(peerAddr, data);
}
void serverThread::disconnectToHost()
{
emit disconnectTCP(socketDescriptor);
socket->disconnectFromHost();
}