The function "sendPing" and "send" is added.

This commit is contained in:
Denis Davydov 2018-05-11 15:23:28 +03:00
parent 9f3baba209
commit 33e436e330

View File

@ -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);
}
}