wfview/tcpserver.h

63 wiersze
1.3 KiB
C
Czysty Zwykły widok Historia

2022-03-23 10:12:42 +00:00
#ifndef TCPSERVER_H
#define TCPSERVER_H
#include <QObject>
#include <QDebug>
2022-03-23 10:12:42 +00:00
#include <QTcpServer>
#include <QTcpSocket>
#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 10:12:42 +00:00
public:
explicit tcpServer(QObject* parent = Q_NULLPTR);
2022-03-23 10:12:42 +00:00
~tcpServer();
int startServer(qint16 port);
void stopServer();
2022-03-23 10:12:42 +00:00
public slots:
virtual void incomingConnection(qintptr socketDescriptor);
void receiveDataFromClient(QByteArray data);
void sendData(QByteArray data);
2022-03-23 10:12:42 +00:00
signals:
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
void sendDataToClient(QByteArray data);
2022-04-03 19:16:52 +00:00
void newClient(int socketId);
2022-03-23 10:12:42 +00:00
private:
QTcpServer* server;
QTcpSocket* socket = Q_NULLPTR;
};
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