2022-03-23 10:12:42 +00:00
|
|
|
#ifndef TCPSERVER_H
|
|
|
|
#define TCPSERVER_H
|
|
|
|
|
2022-03-23 13:19:05 +00:00
|
|
|
#include <QObject>
|
|
|
|
#include <QDebug>
|
2022-03-23 10:12:42 +00:00
|
|
|
#include <QTcpServer>
|
|
|
|
#include <QTcpSocket>
|
2022-03-23 13:19:05 +00:00
|
|
|
#include <QSet>
|
|
|
|
#include <QDataStream>
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
#include <vector>
|
|
|
|
#include <typeindex>
|
|
|
|
|
|
|
|
class tcpServer : public QTcpServer
|
2022-03-23 10:12:42 +00:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
2022-03-23 13:19:05 +00:00
|
|
|
|
2022-03-23 10:12:42 +00:00
|
|
|
public:
|
2022-03-23 13:19:05 +00:00
|
|
|
explicit tcpServer(QObject* parent = Q_NULLPTR);
|
2022-03-23 10:12:42 +00:00
|
|
|
~tcpServer();
|
2022-03-23 13:19:05 +00:00
|
|
|
int startServer(qint16 port);
|
|
|
|
void stopServer();
|
|
|
|
|
2022-03-23 10:12:42 +00:00
|
|
|
public slots:
|
2022-03-23 13:19:05 +00:00
|
|
|
virtual void incomingConnection(qintptr socketDescriptor);
|
|
|
|
void receiveDataFromClient(QByteArray data);
|
|
|
|
void sendData(QByteArray data);
|
2022-03-23 10:12:42 +00:00
|
|
|
signals:
|
2022-03-23 13:19:05 +00:00
|
|
|
void onStarted();
|
|
|
|
void onStopped();
|
2022-04-03 19:16:52 +00:00
|
|
|
void receiveData(QByteArray data); // emit this when we have data from tcp client, connect to rigcommander
|
2022-03-23 13:19:05 +00:00
|
|
|
void sendDataToClient(QByteArray data);
|
2022-04-03 19:16:52 +00:00
|
|
|
void newClient(int socketId);
|
2022-03-23 13:19:05 +00:00
|
|
|
|
2022-03-23 10:12:42 +00:00
|
|
|
private:
|
|
|
|
QTcpServer* server;
|
|
|
|
QTcpSocket* socket = Q_NULLPTR;
|
|
|
|
};
|
|
|
|
|
2022-03-23 13:19:05 +00:00
|
|
|
class tcpServerClient : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit tcpServerClient(int socket, tcpServer* parent = Q_NULLPTR);
|
|
|
|
public slots:
|
|
|
|
void socketReadyRead();
|
|
|
|
void socketDisconnected();
|
|
|
|
void closeSocket();
|
|
|
|
void receiveDataToClient(QByteArray);
|
|
|
|
|
|
|
|
signals:
|
|
|
|
void sendDataFromClient(QByteArray data);
|
|
|
|
protected:
|
|
|
|
int sessionId;
|
|
|
|
QTcpSocket* socket = Q_NULLPTR;
|
|
|
|
|
|
|
|
private:
|
|
|
|
tcpServer* parent;
|
|
|
|
};
|
|
|
|
|
2022-03-23 10:12:42 +00:00
|
|
|
#endif
|