2019-11-20 22:59:23 +08:00
|
|
|
#ifndef EXTCPSERVER_H
|
|
|
|
#define EXTCPSERVER_H
|
|
|
|
|
|
|
|
#include <QMainWindow>
|
2019-11-22 00:12:39 +08:00
|
|
|
#include <QLabel>
|
|
|
|
#include <QTcpServer>
|
|
|
|
#include <QTcpSocket>
|
|
|
|
#include <QHostInfo>
|
2019-11-20 22:59:23 +08:00
|
|
|
|
|
|
|
namespace Ui {
|
|
|
|
class ExTcpServer;
|
|
|
|
}
|
|
|
|
|
|
|
|
class ExTcpServer : public QMainWindow
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit ExTcpServer(QWidget *parent = nullptr);
|
|
|
|
~ExTcpServer();
|
|
|
|
|
2019-11-22 00:12:39 +08:00
|
|
|
private:
|
|
|
|
QString getLocalIp(); //获取本机 IP
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void closeEvent(QCloseEvent* event);
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
//UI的槽函数
|
|
|
|
void on_actStart_triggered(); //开始监听
|
|
|
|
void on_actStop_triggered(); //停止监听
|
|
|
|
void on_actClear_triggered(); //清除文本框内容
|
|
|
|
void on_actQuit_triggered(); //退出程序
|
|
|
|
void on_btnSend_clicked(); //发送消息
|
|
|
|
|
|
|
|
//自定义的槽函数
|
|
|
|
void onSocketReadyRead(); //读取 socket 传入时候的数据
|
|
|
|
void onClientConnected(); //client socket conneted
|
|
|
|
void onClientDisonnected(); //client socket disconneted
|
2019-11-22 22:59:36 +08:00
|
|
|
void onNewConnection(); //QTcpServer 的 newConnect() 信号
|
|
|
|
void onSocketStateChange(QAbstractSocket::SocketState socketState);
|
2019-11-22 00:12:39 +08:00
|
|
|
|
2019-11-20 22:59:23 +08:00
|
|
|
private:
|
|
|
|
Ui::ExTcpServer *ui;
|
2019-11-22 00:12:39 +08:00
|
|
|
|
|
|
|
QLabel* m_labListen;
|
|
|
|
QLabel* m_labSocket;
|
|
|
|
QTcpServer* m_tcpServer;
|
|
|
|
QTcpSocket* m_tcpSocket;
|
|
|
|
|
|
|
|
|
2019-11-20 22:59:23 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // EXTCPSERVER_H
|