network_message.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. //
  2. // Created by huli on 2022/12/30.
  3. //
  4. #ifndef NNXX_TESTS_NETWORK_MESSAGE_H
  5. #define NNXX_TESTS_NETWORK_MESSAGE_H
  6. #include "../error_code/error_code.h"
  7. #include <string>
  8. //网络通信的数据包,
  9. class Network_message
  10. {
  11. public:
  12. Network_message();
  13. Network_message(std::string message_buf, int socket_id, std::string ip, int port);
  14. Network_message(std::string message_buf, int socket_id = 0);
  15. Network_message(const Network_message& other)= default;
  16. Network_message& operator =(const Network_message& other)= default;
  17. ~Network_message();
  18. public://API functions
  19. void reset(std::string message_buf, int socket_id, std::string ip, int port);
  20. void reset(std::string message_buf, int socket_id = 0);
  21. public://get or set member variable
  22. protected://member functions
  23. protected://member variable
  24. public:
  25. //数据包属性
  26. int m_socket_id; //自定义的socket编号, 不能为0
  27. std::string m_ip; //连接的ip, 接受特有, 发送没有
  28. int m_port; //连接的端口, 接受特有, 发送没有
  29. //数据包内容
  30. std::string m_message_buf; //消息数据
  31. private:
  32. };
  33. #endif //NNXX_TESTS_NETWORK_MESSAGE_H