blob: ca2f8259ff7cf3396973805a124f229fafeb74b8 (
plain)
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
|
// Copyright (C) 2016 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Milian Wolff <milian.wolff@kdab.com>
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#include "chatserver.h"
#include "../shared/websocketclientwrapper.h"
#include "../shared/websockettransport.h"
#include <QCoreApplication>
#include <QWebChannel>
#include <QWebSocketServer>
int main(int argc, char** argv)
{
QCoreApplication app(argc, argv);
QWebSocketServer server(QStringLiteral("QWebChannel Standalone Example Server"),
QWebSocketServer::NonSecureMode);
if (!server.listen(QHostAddress::LocalHost, 12345)) {
qFatal("Failed to open web socket server.");
return 1;
}
// wrap WebSocket clients in QWebChannelAbstractTransport objects
WebSocketClientWrapper clientWrapper(&server);
// setup the channel
QWebChannel channel;
QObject::connect(&clientWrapper, &WebSocketClientWrapper::clientConnected,
&channel, &QWebChannel::connectTo);
// setup the dialog and publish it to the QWebChannel
ChatServer* chatserver = new ChatServer(&app);
channel.registerObject(QStringLiteral("chatserver"), chatserver);
return app.exec();
}
|