Initial commit
This commit is contained in:
commit
b7d90b9afe
16245 files changed
+3396666
No files matched your search
@@ -0,0 +1,64 @@
|
||||
/**
|
||||
* Small test program to connect to the wls websocket
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Christian Ehrlicher, SLSE, 2017-01-10
|
||||
*/
|
||||
|
||||
#include "wls_json_client_test.h"
|
||||
#include <QCoreApplication>
|
||||
#include <QStringList>
|
||||
#include <QString>
|
||||
#include <QTimer>
|
||||
|
||||
WlsJsonclientTest::WlsJsonclientTest(const QString &hostname, unsigned short port)
|
||||
: m_socket(new QWebSocket(QString(), QWebSocketProtocol::VersionLatest, this))
|
||||
, m_hostname(hostname)
|
||||
, m_port(port)
|
||||
{
|
||||
connect(m_socket, &QWebSocket::connected, this, &WlsJsonclientTest::onConnected);
|
||||
connect(m_socket, &QWebSocket::disconnected, this, &WlsJsonclientTest::onClosed);
|
||||
connect(m_socket, &QWebSocket::textMessageReceived, this, &WlsJsonclientTest::onTextMessageReceived);
|
||||
QTimer::singleShot(0, this, &WlsJsonclientTest::run);
|
||||
}
|
||||
|
||||
void WlsJsonclientTest::run()
|
||||
{
|
||||
const QUrl url(QStringLiteral("ws://%1:%2/").arg(m_hostname).arg(m_port));
|
||||
qDebug("Trying to connect to %s", qPrintable(url.toString()));
|
||||
m_socket->open(url);
|
||||
}
|
||||
|
||||
void WlsJsonclientTest::onConnected()
|
||||
{
|
||||
qDebug("Connected to web socket server");
|
||||
}
|
||||
|
||||
void WlsJsonclientTest::onClosed()
|
||||
{
|
||||
qWarning("Socket closed - quit app");
|
||||
QCoreApplication::quit();
|
||||
}
|
||||
|
||||
void WlsJsonclientTest::onTextMessageReceived(const QString &msg)
|
||||
{
|
||||
qDebug("Received text msg: '%s'", qPrintable(msg));
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
QCoreApplication app(argc, argv);
|
||||
|
||||
unsigned short port = 12346;
|
||||
QString hostname = QStringLiteral("localhost");
|
||||
if (app.arguments().size() > 1)
|
||||
hostname = app.arguments().at(1);
|
||||
if (app.arguments().size() > 2)
|
||||
port = app.arguments().at(2).toUShort();
|
||||
|
||||
WlsJsonclientTest *w = new WlsJsonclientTest(hostname, port);
|
||||
int ret = app.exec();
|
||||
delete w;
|
||||
return ret;
|
||||
}
|
||||
Reference in new issue
Block a user