// // Created by dongl on 23-5-10. // #ifndef IM2_CLIENT_H #define IM2_CLIENT_H #include #include "event2/event.h" #include "event2/bufferevent.h" class Client { public: Client(const std::string&& ip, int port); virtual ~Client(); void run(); private: void init(const std::string& ip, int port); sockaddr_in addr(const std::string& ip, int port); /// 用户操作函数 public: void send_data(const std::string &data); // 三个回调 private: static void readcb(struct bufferevent *bev, void *ctx); static void writecb(struct bufferevent *bev, void *ctx); static void eventcb(struct bufferevent *bev, short what, void *ctx); private: event_base* base{}; bufferevent* bev{}; event* ev{}; std::string ip; int port; }; #endif //IM2_CLIENT_H