65 lines
1020 B
C++
Executable File
65 lines
1020 B
C++
Executable File
|
|
|
|
#pragma once
|
|
|
|
#include <QtNetwork/QHostAddress>
|
|
#include <QtWebSockets/qwebsocketprotocol.h>
|
|
#include <QtWebSockets/QWebSocketServer>
|
|
|
|
#include "logger.h"
|
|
|
|
namespace LtsWebSocket
|
|
{
|
|
class MessageHandler;
|
|
class ClientConnection;
|
|
class ReplyMessage;
|
|
|
|
|
|
|
|
class ConnectionHandler
|
|
: public QObject
|
|
{
|
|
Q_OBJECT
|
|
public:
|
|
|
|
|
|
explicit ConnectionHandler(QObject *parent = nullptr);
|
|
~ConnectionHandler();
|
|
|
|
|
|
|
|
bool init(const QString &serviceName, unsigned short port);
|
|
|
|
|
|
|
|
void sendToAllClients(ReplyMessage *message);
|
|
|
|
|
|
|
|
unsigned short webSocketPort() { return m_server->serverPort(); }
|
|
|
|
signals:
|
|
|
|
|
|
void newTextMessageFromClient(ClientConnection *client, const QString &message);
|
|
|
|
|
|
|
|
void clientDisconnected(ClientConnection *client);
|
|
|
|
|
|
|
|
void clientConnected(ClientConnection *client);
|
|
|
|
private slots:
|
|
void onServerError(QWebSocketProtocol::CloseCode closeCode);
|
|
void onNewConnection();
|
|
|
|
private:
|
|
QWebSocketServer *m_server;
|
|
QSet<ClientConnection *> m_connections;
|
|
LOGGER_T m_logger;
|
|
|
|
};
|
|
}
|