TCPClient.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * @Description: TCPClient
  3. * @Version: 1.0
  4. * @Autor: lishengyin
  5. * @Date: 2021-09-13 17:30:20
  6. * @LastEditors: lishengyin
  7. * @LastEditTime: 2021-10-15 15:46:34
  8. */
  9. #pragma once
  10. #include <signal.h>
  11. #include <iostream>
  12. #include "Util/logger.h"
  13. #include "Network/TcpClient.h"
  14. #include "Util/NoticeCenter.h"
  15. #include "Notices.h"
  16. using namespace std;
  17. using namespace toolkit;
  18. // dataType
  19. #include "SendLogin.h"
  20. #include "NettyServerCommandEnum.h"
  21. #include "NettyServerResultMsg.h"
  22. #include "NettyClientResultMsg.h"
  23. #include "SendLogin.h"
  24. #include "NettyClientCommandEnum.h"
  25. #include "SendHeartBeat.h"
  26. namespace MIVA
  27. {
  28. class TCPClient: public TcpClient
  29. {
  30. private:
  31. /* data */
  32. public:
  33. typedef std::shared_ptr<TCPClient> Ptr;
  34. TCPClient():TcpClient() {
  35. DebugL;
  36. }
  37. ~TCPClient(){
  38. DebugL;
  39. }
  40. protected:
  41. /**
  42. * @description: 连接成功时触发
  43. * @param {SockException} &ex 连接info
  44. * @return {*}
  45. * @author: lishengyin
  46. */
  47. virtual void onConnect(const SockException &ex) override;
  48. /**
  49. * @description: 接收数据时触发
  50. * @param {Ptr} &pBuf 接受到的数据
  51. * @return {*}
  52. * @author: lishengyin
  53. */
  54. virtual void onRecv(const Buffer::Ptr &pBuf) override;
  55. /**
  56. * @description: 发送阻塞时触发
  57. * @param {*}
  58. * @return {*}
  59. * @author: lishengyin
  60. */
  61. virtual void onFlush() override;
  62. /**
  63. * @description: EOF时触发
  64. * @param {SockException} &ex 错误信息
  65. * @return {*}
  66. * @author: lishengyin
  67. */
  68. virtual void onErr(const SockException &ex) override;
  69. /**
  70. * @description: 心跳 2S触发一次
  71. * @param {*}
  72. * @return {*}
  73. * @author: lishengyin
  74. */
  75. virtual void onManager() override;
  76. private:
  77. int _nTick = 0;
  78. std::string _IP;
  79. int32_t _port;
  80. };
  81. } // namespace VIA