main.cpp Example File
chatserver-cpp/main.cpp
#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;
}
WebSocketClientWrapper clientWrapper(&server);
QWebChannel channel;
QObject::connect(&clientWrapper, &WebSocketClientWrapper::clientConnected,
&channel, &QWebChannel::connectTo);
ChatServer* chatserver = new ChatServer(&app);
channel.registerObject(QStringLiteral("chatserver"), chatserver);
return app.exec();
}