diff --git a/src/network.cpp b/src/network.cpp index cc46b45..7c86cd6 100644 --- a/src/network.cpp +++ b/src/network.cpp @@ -1,6 +1,28 @@ -#include "network.h" - -network::network() -{ - -} +#include "network.h" + +class Network +{ + Network() + { + socket = new QUdpSocket(this); + socket->bind(QHostAddress::AnyIPv6, 6552); + connect(socket, SIGNAL(readyRead()), SLOT(read())); + } + void sendPing(QHostAddress ip) + { + json ping; + ping["action"] = "ping"; + QString str = ping.dump(); + send(str, ip); + } + void send(QString str, QHostAddress ip) + { + QByteArray data; + QDataStream out(&data, QIODevice::WriteOnly); + out << qint64(0); + out << str; + out.device()->seek(qint64(0)); + out << qint64(data.size() - sizeof(qint64)); + socket->writeDatagram(data, QHostAddress(ip), 6552); + } +}