forked from Sepanta/console-emulator
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.
54 lines
1.8 KiB
54 lines
1.8 KiB
#include "network/UdpDataSender.h"
|
|
|
|
#define DATAGRAM_SIZE 8
|
|
|
|
void UdpDataSender::send(const QByteArray& data)
|
|
{
|
|
_socketDashboard->writeDatagram(data, QHostAddress::LocalHost, 5446);
|
|
}
|
|
|
|
/*************************************************************************************************/
|
|
void UdpDataSender::sendProbeSlots(const QByteArray& data)
|
|
{
|
|
_socketProbeSlots->writeDatagram(data, QHostAddress::LocalHost, 5450);
|
|
}
|
|
|
|
/*************************************************************************************************/
|
|
void UdpDataSender::read()
|
|
{
|
|
char data[DATAGRAM_SIZE];
|
|
int cnt = _socketDashboard->readDatagram(data, DATAGRAM_SIZE);
|
|
QByteArray a(data, cnt);
|
|
emit dataReady(a);
|
|
}
|
|
|
|
/*************************************************************************************************/
|
|
void UdpDataSender::readProbeSlots()
|
|
{
|
|
char data[DATAGRAM_SIZE];
|
|
int cnt = _socketProbeSlots->readDatagram(data, DATAGRAM_SIZE);
|
|
QByteArray a(data, cnt);
|
|
emit probeSlotsDataReady(a);
|
|
}
|
|
|
|
/*************************************************************************************************/
|
|
UdpDataSender::UdpDataSender()
|
|
{
|
|
_socketDashboard = new QUdpSocket();
|
|
_socketDashboard->bind(QHostAddress::Any, 5445);
|
|
connect(_socketDashboard, SIGNAL(readyRead()), this, SLOT(read()));
|
|
|
|
_socketProbeSlots = new QUdpSocket();
|
|
_socketProbeSlots->bind(QHostAddress::Any, 5449);
|
|
connect(_socketProbeSlots, SIGNAL(readyRead()), this, SLOT(readProbeSlots()));
|
|
}
|
|
|
|
/*************************************************************************************************/
|
|
UdpDataSender::~UdpDataSender()
|
|
{
|
|
_socketDashboard->close();
|
|
delete _socketDashboard;
|
|
|
|
_socketProbeSlots->close();
|
|
delete _socketProbeSlots;
|
|
}
|
|
|