TcpServer.h 736 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #ifndef _TCPSERVER_H_
  2. #define _TCPSERVER_H_
  3. #include <QTcpServer>
  4. class TcpServer : public QTcpServer
  5. {
  6. Q_OBJECT
  7. public:
  8. explicit TcpServer(QObject *parent = nullptr);
  9. ~TcpServer() override;
  10. /* 启动服务器 */
  11. bool startServer(quint16 port);
  12. /* 停止服务器 */
  13. void stopServer();
  14. private slots:
  15. /* 接收监听信息 */
  16. void do_newConnection();
  17. /* 处理客户端断开连接 */
  18. void do_clientDisconnected();
  19. /* 接收消息 */
  20. void do_readyRead();
  21. /* 发送消息 */
  22. void do_sendMessage(QTcpSocket* pSocket, const QByteArray& message);
  23. private:
  24. private:
  25. std::list<QTcpSocket*> m_listClients; /* 客户端列表 */
  26. };
  27. #endif // _TCPSERVER_H_