-
Notifications
You must be signed in to change notification settings - Fork 1
/
myudp.cpp
44 lines (28 loc) · 805 Bytes
/
myudp.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include "myudp.h"
#include <QDebug>
MyUDP::MyUDP(QObject* parent):QObject (parent)
{
socket = new QUdpSocket(this);
socket->bind(QHostAddress::LocalHost,5678);
connect(socket,SIGNAL(readyRead()),this,SLOT(ReadData()));
}
void MyUDP::WriteData()
{
QByteArray msg;
msg.append("Hello");
socket->writeDatagram(msg,QHostAddress::LocalHost,5678);
}
void MyUDP::ReadData()
{
QByteArray buffer;
buffer.resize(socket->pendingDatagramSize());
QHostAddress sender;
quint16 port;
socket->readDatagram(buffer.data(),
buffer.size(),
&sender,
&port);
qDebug() << "Message From" << sender.toString();
qDebug() << "With Port No:" << port;
qDebug() << "Message" << buffer;
}