56 lines
1.1 KiB
C
56 lines
1.1 KiB
C
|
#ifndef TCPSERVER_H
|
||
|
#define TCPSERVER_H
|
||
|
|
||
|
#include <QObject>
|
||
|
#include <QTcpSocket>
|
||
|
#include <QTcpServer>
|
||
|
|
||
|
#define PORT 5000
|
||
|
|
||
|
struct CommMsg
|
||
|
{
|
||
|
QString ip;
|
||
|
int port;
|
||
|
QByteArray buf;
|
||
|
int size; //buf的字节数
|
||
|
};
|
||
|
|
||
|
struct CTcpClient
|
||
|
{
|
||
|
QString ip;
|
||
|
int port;
|
||
|
QTcpSocket* socket;
|
||
|
};
|
||
|
|
||
|
class TcpServer : public QObject
|
||
|
{
|
||
|
Q_OBJECT
|
||
|
public:
|
||
|
explicit TcpServer(QObject *parent = nullptr);
|
||
|
~TcpServer();
|
||
|
|
||
|
private:
|
||
|
QTcpServer *m_server;
|
||
|
QList<CTcpClient> m_clientList;
|
||
|
QTcpSocket *m_curSocket;
|
||
|
|
||
|
private slots:
|
||
|
void slotNewConnect();//新的客户端连接
|
||
|
void slotDisConnect(); //客户端断开连接
|
||
|
|
||
|
signals:
|
||
|
void siNewClient(const QString ip, const int port, int add); //新的客户端
|
||
|
void siNewMsg(const CommMsg dat); //发送给客户端的消息
|
||
|
void siDisConncet(const QString ip, const int port, int red); //客户端断开连接
|
||
|
|
||
|
public slots:
|
||
|
void slotInit();
|
||
|
void slotRecvData();
|
||
|
void slotSendData(CommMsg msg);
|
||
|
void slotStopMonitor();
|
||
|
void slotStartMonitor();
|
||
|
|
||
|
};
|
||
|
|
||
|
#endif // TCPSERVER_H
|