|
@@ -0,0 +1,29 @@
|
|
1
|
+#include <QDataStream>
|
|
2
|
+#include "servermanager.h"
|
|
3
|
+
|
|
4
|
+ServerManager::ServerManager(QObject *parent)
|
|
5
|
+ : QObject(parent)
|
|
6
|
+ , m_server(new PTServer(this))
|
|
7
|
+{
|
|
8
|
+}
|
|
9
|
+
|
|
10
|
+bool ServerManager::init(const QHostAddress &addr, const int &port)
|
|
11
|
+{
|
|
12
|
+ return m_server->listen(addr, port);
|
|
13
|
+}
|
|
14
|
+
|
|
15
|
+void ServerManager::sendData(const QList<QVariant> &values, const qint64 ×tamp)
|
|
16
|
+{
|
|
17
|
+ auto clients = m_server->getClients();
|
|
18
|
+ if (!clients.count())
|
|
19
|
+ return;
|
|
20
|
+ QByteArray data;
|
|
21
|
+ QDataStream stream(&data, QIODevice::WriteOnly);
|
|
22
|
+
|
|
23
|
+ stream << timestamp << values.count();
|
|
24
|
+ foreach (auto value, values)
|
|
25
|
+ stream << value;
|
|
26
|
+ foreach (auto client, clients)
|
|
27
|
+ client->send(1, data);
|
|
28
|
+}
|
|
29
|
+
|