File: UdpTcpPublisher.cpp

package info (click to toggle)
labplot 2.12.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 78,500 kB
  • sloc: cpp: 241,048; ansic: 6,324; python: 915; xml: 400; yacc: 237; sh: 221; awk: 35; makefile: 11
file content (27 lines) | stat: -rw-r--r-- 673 bytes parent folder | download | duplicates (2)
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
#include <QCoreApplication>
#include <QDebug>
#include <QThread>
#include <QTimer>
#include <QUdpSocket>

int main(int argc, char* argv[]) {
	QCoreApplication a(argc, argv);

	int udpNewDataUpdateTimeMs = PUBLISH_TIME_MS;
	int udpPort = UDP_PORT;
	QString hostname = QStringLiteral(HOSTNAME);

	// initialize the UDP socket
	QUdpSocket udpSocket(&a);
	if (!udpSocket.bind(QHostAddress(hostname), 56080)) {
		exit(-3);
		return -3;
	}
	QTimer timer(&a);
	QCoreApplication::connect(&timer, &QTimer::timeout, [&udpSocket, udpPort, hostname]() {
		udpSocket.writeDatagram("1,2", QHostAddress(hostname), udpPort);
	});
	timer.start(udpNewDataUpdateTimeMs);

	return a.exec();
}