Samchon Framework for CPP  1.0.0
IWebClientBase.hpp
1 #pragma once
2 #include <samchon/API.hpp>
3 
4 #include <samchon/protocol/IClient.hpp>
5 
6 namespace boost
7 {
8 namespace system
9 {
10  class error_code;
11 };
12 };
13 namespace samchon
14 {
15 namespace protocol
16 {
17  enum ENUM_DIRECTION
18  {
19  SERVER = 1,
20  CLIENT = 2
21  };
22 
32  class SAMCHON_FRAMEWORK_API IWebClientBase
33  : public virtual IClient
34  {
35  protected:
36  typedef IClient super;
37 
38  static const unsigned char TEXT_HEADER = 129;
39  static const unsigned char BINARY_HEADER = 130;
40 
41  public:
42  /* -----------------------------------------------------------------------
43  CONSTRUCTORS
44  ----------------------------------------------------------------------- */
49  virtual ~IWebClientBase() = default;
50 
51  protected:
52  virtual auto DIRECTION() const->ENUM_DIRECTION = 0;
53 
54 
55  public:
56  /* -----------------------------------------------------------------------
57  LISTEN MESSAGE
58  ----------------------------------------------------------------------- */
59  virtual void listen() override;
60 
61  private:
62  auto listenString(size_t, ByteArray&, boost::system::error_code &)->std::shared_ptr<Invoke>;
63  void listenBinary(size_t, ByteArray&, std::shared_ptr<Invoke>, boost::system::error_code &);
64 
65  void listenMoreBytes(ByteArray&, boost::system::error_code &);
66 
67  /* -----------------------------------------------------------------------
68  SEND MESSAGE
69  ----------------------------------------------------------------------- */
70  public:
71  virtual void sendData(std::shared_ptr<Invoke>) override;
72 
73  private:
74  void sendSizeHeader(unsigned char, size_t, boost::system::error_code &);
75 
76  void sendString(const std::string &, boost::system::error_code &);
77  void sendBinary(const ByteArray &, boost::system::error_code &);
78  };
79 };
80 };
An interface for a client.
Definition: IClient.hpp:53
An interface for a web-client.
Standard message of network I/O.
Definition: Invoke.hpp:47
Binary data class.
Definition: ByteArray.hpp:30
Top level namespace of products built from samchon.
Definition: ByteArray.hpp:7