CClientSession.h 826 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. void handle_write(const boost::system::error_code& error);
  33. tcp::socket socket_;
  34. enum { max_length = 1024 };
  35. char data_[max_length];
  36. CServer* m_server;
  37. int m_nClientNum;
  38. std::string m_username = "";
  39. };