TCPClient.h 2.4 KB

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