CClientSession.h 661 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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 send_message(std::string msg);
  20. private:
  21. void handle_read(const boost::system::error_code& error,
  22. size_t bytes_transferred);
  23. void handle_write(const boost::system::error_code& error);
  24. tcp::socket socket_;
  25. enum { max_length = 1024 };
  26. char data_[max_length];
  27. CServer* m_server;
  28. };