#ifndef HV_WEBSOCKET_CLIENT_H_ #define HV_WEBSOCKET_CLIENT_H_ /* * @demo examples/websocket_client_test.cpp */ #include "hexport.h" #include "TcpClient.h" #include "WebSocketChannel.h" #include "HttpParser.h" #include "WebSocketParser.h" namespace hv { class HV_EXPORT WebSocketClient : public TcpClientTmpl { public: std::string url; std::function onopen; std::function onclose; std::function onmessage; WebSocketClient(); ~WebSocketClient(); // ws://127.0.0.1:8080/ int open(const char* url); int close(); int send(const std::string& msg); private: enum State { CONNECTING, CONNECTED, WS_UPGRADING, WS_OPENED, WS_CLOSED, } state; HttpParserPtr http_parser; HttpRequestPtr http_req; HttpResponsePtr http_resp; WebSocketParserPtr ws_parser; }; } #endif // HV_WEBSOCKET_CLIENT_H_