-
Notifications
You must be signed in to change notification settings - Fork 83
Expand file tree
/
Copy pathapplive.cpp
More file actions
47 lines (38 loc) · 1 KB
/
applive.cpp
File metadata and controls
47 lines (38 loc) · 1 KB
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
#if _MSC_VER >= 1600
#pragma execution_character_set("utf-8")
#endif
#include "applive.h"
#include "myhelper.h"
AppLive *AppLive::_instance = 0;
AppLive::AppLive(QObject *parent) : QObject(parent)
{
udpServer = new QUdpSocket(this);
}
bool AppLive::Start(int port)
{
bool ok = udpServer->bind(port);
if (ok) {
connect(udpServer, SIGNAL(readyRead()), this, SLOT(ReadData()));
qDebug() << TIMEMS << "Start AppLive Ok";
}
return ok;
}
void AppLive::Stop()
{
udpServer->abort();
disconnect(udpServer, SIGNAL(readyRead()), this, SLOT(ReadData()));
}
void AppLive::ReadData()
{
QByteArray tempData;
do {
tempData.resize(udpServer->pendingDatagramSize());
QHostAddress sender;
quint16 senderPort;
udpServer->readDatagram(tempData.data(), tempData.size(), &sender, &senderPort);
QString data = QLatin1String(tempData);
if (data == "hello") {
udpServer->writeDatagram(QString("%1OK").arg(App::AppName).toLatin1(), sender, senderPort);
}
} while (udpServer->hasPendingDatagrams());
}