You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

servermanager.cpp 729B

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