2019-09-29 05:13:01 +00:00
|
|
|
|
#ifndef TCPSERVER_H
|
|
|
|
|
#define TCPSERVER_H
|
|
|
|
|
|
2021-01-24 08:04:48 +00:00
|
|
|
|
#include "tcpclient.h"
|
2019-09-29 05:13:01 +00:00
|
|
|
|
|
|
|
|
|
class TcpServer : public QTcpServer
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
public:
|
|
|
|
|
explicit TcpServer(QObject *parent = 0);
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
QList<TcpClient *> clients;
|
|
|
|
|
|
|
|
|
|
private slots:
|
2021-01-24 08:04:48 +00:00
|
|
|
|
void newConnection();
|
2019-09-29 05:13:01 +00:00
|
|
|
|
void disconnected();
|
|
|
|
|
|
|
|
|
|
signals:
|
|
|
|
|
void sendData(const QString &ip, int port, const QString &data);
|
|
|
|
|
void receiveData(const QString &ip, int port, const QString &data);
|
|
|
|
|
|
|
|
|
|
void clientConnected(const QString &ip, int port);
|
|
|
|
|
void clientDisconnected(const QString &ip, int port);
|
|
|
|
|
|
|
|
|
|
public slots:
|
|
|
|
|
//启动服务
|
|
|
|
|
bool start();
|
|
|
|
|
//停止服务
|
|
|
|
|
void stop();
|
|
|
|
|
|
|
|
|
|
//指定连接发送数据
|
|
|
|
|
void writeData(const QString &ip, int port, const QString &data);
|
|
|
|
|
//对所有连接发送数据
|
|
|
|
|
void writeData(const QString &data);
|
|
|
|
|
|
|
|
|
|
//断开指定连接
|
|
|
|
|
void remove(const QString &ip, int port);
|
|
|
|
|
//断开所有连接
|
|
|
|
|
void remove();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif // TCPSERVER_H
|