Files
autopilot/misc/udp/udp_client/main.cpp
T
Tuomas Järvinen 45c19baa45 Changed directory structure and renamed applications
- autopilot -> drone_controller
- rtsp_ai_player -> ai_controller
- added top level qmake project file
- updated documentation
- moved small demo applications from tmp/ to misc/
2024-10-19 14:44:34 +02:00

40 lines
968 B
C++

#include <QCoreApplication>
#include <QUdpSocket>
#include <QHostAddress>
#include <QThread>
#include <QJsonObject>
#include <QJsonDocument>
int main(int argc, char *argv[]) {
QCoreApplication a(argc, argv);
if (argc != 2) {
qDebug() << "Give port number of server as only parameter";
return 1;
}
QUdpSocket udpSocket;
quint16 receiverPort = atoi(argv[1]);
for (int i = 0; i < 10000000 ; i++) {
QJsonObject json;
json["value"] = i;
QJsonDocument jsonDoc(json);
QByteArray datagram = jsonDoc.toJson();
qint64 bytesSent = udpSocket.writeDatagram(datagram, QHostAddress("127.0.0.1"), receiverPort);
if (bytesSent == -1) {
qWarning("Failed to send the datagram: %s", qPrintable(udpSocket.errorString()));
return 1;
}
else {
qDebug("Datagram sent successfully");
}
QThread::msleep(100);
}
return 0;
}