CClientSession.h 765 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #pragma once
  2. #include "../pch/pch.h"
  3. using boost::asio::ip::tcp;
  4. class CServer;
  5. class CClientSession
  6. {
  7. public:
  8. CClientSession(boost::asio::io_context& io_context)
  9. : socket_(io_context)
  10. {
  11. }
  12. ~CClientSession();
  13. void SetServer(CServer* server);
  14. tcp::socket& socket()
  15. {
  16. return socket_;
  17. }
  18. void start();
  19. void stop();
  20. void send_message(std::string msg);
  21. void SetNum(int m_num)
  22. {
  23. m_nClientNum = m_num;
  24. }
  25. int GetNum()
  26. {
  27. return m_nClientNum;
  28. }
  29. private:
  30. void handle_read(const boost::system::error_code& error,
  31. size_t bytes_transferred);
  32. tcp::socket socket_;
  33. enum { max_length = 1024 };
  34. char data_[max_length];
  35. CServer* m_server;
  36. int m_nClientNum;
  37. std::string m_username = "";
  38. };