1
This commit is contained in:
parent
548150779d
commit
afdc699fb7
@ -7,8 +7,9 @@
|
|||||||
namespace a8
|
namespace a8
|
||||||
{
|
{
|
||||||
|
|
||||||
WebSocketClient::WebSocketClient(asio::io_context& io_context, const std::string& remote_ip, int remote_port): AsioTcpClient(io_context, remote_ip, remote_port)
|
WebSocketClient::WebSocketClient(asio::io_context& io_context, const std::string& remote_ip, int remote_port)
|
||||||
{
|
{
|
||||||
|
tcp_client_ = std::make_shared<AsioTcpClient>(io_context, remote_ip, remote_port);
|
||||||
decoded_buff_ = (char *)malloc(1024 * 64 + 1);
|
decoded_buff_ = (char *)malloc(1024 * 64 + 1);
|
||||||
decoded_bufflen_ = 0;
|
decoded_bufflen_ = 0;
|
||||||
}
|
}
|
||||||
@ -20,6 +21,33 @@ namespace a8
|
|||||||
decoded_bufflen_ = 0;
|
decoded_bufflen_ = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WebSocketClient::Open()
|
||||||
|
{
|
||||||
|
tcp_client_->Open();
|
||||||
|
}
|
||||||
|
|
||||||
|
void WebSocketClient::Close()
|
||||||
|
{
|
||||||
|
tcp_client_->Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool WebSocketClient::IsActive()
|
||||||
|
{
|
||||||
|
return tcp_client_->IsActive();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool WebSocketClient::Connected()
|
||||||
|
{
|
||||||
|
return tcp_client_->Connected();
|
||||||
|
}
|
||||||
|
|
||||||
|
void WebSocketClient::SendBuff(const char* buff, unsigned int bufflen)
|
||||||
|
{
|
||||||
|
if (!handshook_) {
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -11,13 +11,25 @@ using asio::ip::tcp;
|
|||||||
namespace a8
|
namespace a8
|
||||||
{
|
{
|
||||||
|
|
||||||
class WebSocketClient : public AsioTcpClient
|
class WebSocketClient
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
WebSocketClient(asio::io_context& io_context, const std::string& remote_ip, int remote_port);
|
WebSocketClient(asio::io_context& io_context, const std::string& remote_ip, int remote_port);
|
||||||
virtual ~WebSocketClient() override;
|
virtual ~WebSocketClient();
|
||||||
|
|
||||||
|
std::function<void (a8::WebSocketClient*, int)> on_error;
|
||||||
|
std::function<void (a8::WebSocketClient*)> on_connect;
|
||||||
|
std::function<void (a8::WebSocketClient*)> on_disconnect;
|
||||||
|
std::function<void (a8::WebSocketClient*, char*, unsigned int)> on_socketread;
|
||||||
|
|
||||||
|
void Open();
|
||||||
|
void Close();
|
||||||
|
bool IsActive();
|
||||||
|
bool Connected();
|
||||||
|
void SendBuff(const char* buff, unsigned int bufflen);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
std::shared_ptr<AsioTcpClient> tcp_client_;
|
||||||
char *decoded_buff_ = nullptr;
|
char *decoded_buff_ = nullptr;
|
||||||
int decoded_bufflen_ = 0;
|
int decoded_bufflen_ = 0;
|
||||||
bool handshook_ = false;
|
bool handshook_ = false;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user