Browse Source

server manager

old
Robin Thoni 9 years ago
parent
commit
b9fa73c9c6
2 changed files with 54 additions and 0 deletions
  1. 29
    0
      server/servermanager.cpp
  2. 25
    0
      server/servermanager.h

+ 29
- 0
server/servermanager.cpp View File

@@ -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 &timestamp)
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
+

+ 25
- 0
server/servermanager.h View File

@@ -0,0 +1,25 @@
1
+#ifndef SERVERMANAGER_H
2
+#define SERVERMANAGER_H
3
+
4
+#include <QObject>
5
+#include <ptsocket/ptserver.h>
6
+
7
+class ServerManager : public QObject
8
+{
9
+    Q_OBJECT
10
+public:
11
+    explicit ServerManager(QObject *parent = 0);
12
+
13
+signals:
14
+
15
+public slots:
16
+    bool init(const QHostAddress& addr, const int& port);
17
+
18
+    void sendData(const QList<QVariant> &values, const qint64& timestamp);
19
+
20
+private:
21
+    PTServer* m_server;
22
+
23
+};
24
+
25
+#endif // SERVERMANAGER_H

Loading…
Cancel
Save