Add websocketlogger
This commit is contained in:
@@ -3,7 +3,8 @@ TEMPLATE = subdirs
|
|||||||
SUBDIRS += \
|
SUBDIRS += \
|
||||||
espremoteagent \
|
espremoteagent \
|
||||||
espremotemanager \
|
espremotemanager \
|
||||||
webserver
|
webserver \
|
||||||
|
websocketlogger
|
||||||
|
|
||||||
espremoteagent.depends += webserver
|
espremoteagent.depends += webserver
|
||||||
espremotemanager.depends += webserver
|
espremotemanager.depends += webserver
|
||||||
|
55
websocketlogger/main.cpp
Normal file
55
websocketlogger/main.cpp
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
#include <QCoreApplication>
|
||||||
|
#include <QWebSocket>
|
||||||
|
#include <QCommandLineParser>
|
||||||
|
#include <QTimer>
|
||||||
|
|
||||||
|
#include <cstdio>
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
QCoreApplication app{argc, argv};
|
||||||
|
QCoreApplication::setApplicationName("websocketlogger");
|
||||||
|
QCoreApplication::setApplicationVersion("1.0");
|
||||||
|
|
||||||
|
QCommandLineParser parser;
|
||||||
|
parser.setApplicationDescription("V3 Produktionstool");
|
||||||
|
parser.addHelpOption();
|
||||||
|
parser.addVersionOption();
|
||||||
|
parser.addPositionalArgument("url", QCoreApplication::translate("main", "Websocket url"));
|
||||||
|
|
||||||
|
parser.process(app);
|
||||||
|
|
||||||
|
const QStringList args = parser.positionalArguments();
|
||||||
|
|
||||||
|
if (args.isEmpty())
|
||||||
|
qFatal("no url specified!");
|
||||||
|
|
||||||
|
QUrl url = QUrl::fromUserInput(args.first());
|
||||||
|
if (!url.isValid())
|
||||||
|
qFatal("invalid url");
|
||||||
|
|
||||||
|
QWebSocket socket;
|
||||||
|
|
||||||
|
const auto connect = [&](){
|
||||||
|
qDebug() << "connecting to" << url;
|
||||||
|
socket.open(url);
|
||||||
|
};
|
||||||
|
|
||||||
|
QObject::connect(&socket, &QWebSocket::connected, [](){
|
||||||
|
qDebug() << "connected";
|
||||||
|
});
|
||||||
|
QObject::connect(&socket, &QWebSocket::disconnected, [&](){
|
||||||
|
qDebug() << "disconnected";
|
||||||
|
QTimer::singleShot(5000, &socket, connect);
|
||||||
|
});
|
||||||
|
QObject::connect(&socket, &QWebSocket::textMessageReceived, [](const QString &message){
|
||||||
|
printf("%s\n", message.toStdString().c_str());
|
||||||
|
});
|
||||||
|
QObject::connect(&socket, &QWebSocket::binaryMessageReceived, [](){
|
||||||
|
qDebug() << "binaryMessageReceived";
|
||||||
|
});
|
||||||
|
|
||||||
|
connect();
|
||||||
|
|
||||||
|
return app.exec();
|
||||||
|
}
|
25
websocketlogger/websocketlogger.pro
Normal file
25
websocketlogger/websocketlogger.pro
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
QT = core network websockets
|
||||||
|
|
||||||
|
TARGET = websocketlogger
|
||||||
|
|
||||||
|
TEMPLATE = app
|
||||||
|
|
||||||
|
CONFIG += console
|
||||||
|
CONFIG -= app_bundle
|
||||||
|
|
||||||
|
PROJECT_ROOT = ..
|
||||||
|
|
||||||
|
DESTDIR = $${OUT_PWD}/$${PROJECT_ROOT}/bin
|
||||||
|
|
||||||
|
DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
|
||||||
|
|
||||||
|
DBLIBS +=
|
||||||
|
|
||||||
|
HEADERS +=
|
||||||
|
|
||||||
|
SOURCES += \
|
||||||
|
main.cpp
|
||||||
|
|
||||||
|
OTHER_FILES +=
|
||||||
|
|
||||||
|
include($${PROJECT_ROOT}/project.pri)
|
Reference in New Issue
Block a user