1234567891011121314151617181920212223242526272829 |
- #include <QDataStream>
- #include "servermanager.h"
-
- ServerManager::ServerManager(QObject *parent)
- : QObject(parent)
- , m_server(new PTServer(this))
- {
- }
-
- bool ServerManager::init(const QHostAddress &addr, const int &port)
- {
- return m_server->listen(addr, port);
- }
-
- void ServerManager::sendData(const QList<QPair<QVariant, QVariant>> &values, const qint64 ×tamp)
- {
- auto clients = m_server->getClients();
- if (!clients.count())
- return;
- QByteArray data;
- QDataStream stream(&data, QIODevice::WriteOnly);
-
- stream << timestamp << values.count();
- foreach (auto value, values)
- stream << value.first << value.second;
- foreach (auto client, clients)
- client->send(1, data);
- }
|