From 4fcdd48a6bfba7d3967423e1d524d0f16918fa74 Mon Sep 17 00:00:00 2001 From: zcy <290198252@qq.com> Date: Fri, 11 Mar 2022 00:33:50 +0800 Subject: [PATCH] no message --- examples/proto_debuger/base_form.cpp | 9 ++++++ examples/proto_debuger/proto_debuger.vcxproj | 7 +++-- .../proto_debuger/websocket_client_form.cpp | 28 +++++++++++++++++-- .../proto_debuger/websocket_client_form.h | 3 ++ 4 files changed, 42 insertions(+), 5 deletions(-) diff --git a/examples/proto_debuger/base_form.cpp b/examples/proto_debuger/base_form.cpp index 2623e9ee..ce59be46 100644 --- a/examples/proto_debuger/base_form.cpp +++ b/examples/proto_debuger/base_form.cpp @@ -4,6 +4,8 @@ #include "utils.h" #include "global.h" #include "websocket_client.h" +#include + const std::wstring BasicForm::kClassName = L"Basic"; BasicForm::BasicForm(): @@ -212,6 +214,13 @@ LRESULT BasicForm::HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam) { WebsocketClient* client = (WebsocketClient*)lParam; auto form = new WebsocketClientForm(this, wstring2string(info->ip),client); + client->SetOnConnectedHandler(std::bind(&WebsocketClientForm::OnConnected, + form, std::placeholders::_1)); + client->SetOnDisConnectedHandler(std::bind(&WebsocketClientForm::OnDisConnected, + form, std::placeholders::_1, std::placeholders::_2)); + client->SetOnReadHandler(std::bind(&WebsocketClientForm::OnReadHandler, + form, std::placeholders::_1, std::placeholders::_2)); + form->SetChildLayoutXML(L"basic/tcp_server_form.xml"); form->SetName(key); form->SetVisible(false); diff --git a/examples/proto_debuger/proto_debuger.vcxproj b/examples/proto_debuger/proto_debuger.vcxproj index 4d445ef4..8dffd5ca 100644 --- a/examples/proto_debuger/proto_debuger.vcxproj +++ b/examples/proto_debuger/proto_debuger.vcxproj @@ -81,9 +81,9 @@ true - $(VC_IncludePath);$(WindowsSDK_IncludePath);..\..\;$(ProjectDir)third\include\libevent\include;$(ProjectDir);$(ProjectDir)third\include\lua;$(ProjectDir)third\include\;D:\include;E:\conan_data\OPENSSL\1.1.1\_\_\build\0ec50343443903d4bfcd42b174a43ee3f59cc16e\pkgsrc\include + $(VC_IncludePath);$(WindowsSDK_IncludePath);..\..\;$(ProjectDir)third\include\libevent\include;$(ProjectDir);$(ProjectDir)third\include\lua;$(ProjectDir)third\include\;D:\include;I:\home\.conan\data\OPENSSL\1.1.1\_\_\build\149ed843ea788702da310f9d8f34c34c2a72994a\pkgsrc\inc32 $(ReferencePath) - $(VC_LibraryPath_x64);$(WindowsSDK_LibraryPath_x64);$(ProjectDir)third\lib;E:\conan_data\OPENSSL\1.1.1\_\_\build\0ec50343443903d4bfcd42b174a43ee3f59cc16e\pkgsrc + $(VC_LibraryPath_x64);$(WindowsSDK_LibraryPath_x64);$(ProjectDir)third\lib;I:\home\.conan\data\OPENSSL\1.1.1\_\_\build\149ed843ea788702da310f9d8f34c34c2a72994a\pkgsrc\out32dll false @@ -132,7 +132,7 @@ Windows true - ws2_32.lib;event_extra.lib;event_core.lib;event.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;lua53.lib;libcrypto_static.lib;libssl_static.lib;Bcrypt.lib;libcmtd.lib;%(AdditionalDependencies) + ws2_32.lib;event_extra.lib;event_core.lib;event.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;lua53.lib;ssleay32.lib;libeay32.lib;Bcrypt.lib;libcmtd.lib;%(AdditionalDependencies) @@ -212,6 +212,7 @@ + diff --git a/examples/proto_debuger/websocket_client_form.cpp b/examples/proto_debuger/websocket_client_form.cpp index 2e91ceb4..a6735838 100644 --- a/examples/proto_debuger/websocket_client_form.cpp +++ b/examples/proto_debuger/websocket_client_form.cpp @@ -12,6 +12,7 @@ WebsocketClientForm::WebsocketClientForm(ui::Window* hwnd, string url, Websocket WebsocketClientForm::~WebsocketClientForm() { + } void WebsocketClientForm::Init() @@ -29,8 +30,7 @@ void WebsocketClientForm::Init() m_btn_close_form = dynamic_cast(FindSubControl(L"btn_close_uart")); if (nullptr != m_label_1) { - if (mWebsocketClient->State() == WebsocketClient::CONNECTED) - { + if (mWebsocketClient->State() == WebsocketClient::CONNECTED) { m_label_1->SetText(std::wstring() + L"服务端: " + string2wstring(mWebsocketClient->Url()) + L"连接成功"); } @@ -73,3 +73,27 @@ void WebsocketClientForm::ShowDataInEdit(const char*src) { m_rich_edit_1->AppendText(string2wstring(std::string(src)),false); } + +void WebsocketClientForm::OnConnected(WebsocketClient* ws) +{ + if (nullptr != m_label_1) { + if (mWebsocketClient->State() == WebsocketClient::CONNECTED) { + m_label_1->SetText(std::wstring() + L"服务端: " + + string2wstring(mWebsocketClient->Url()) + L"连接成功"); + } + else { + m_label_1->SetText(std::wstring() + L"服务端: " + + string2wstring(mWebsocketClient->Url()) + L"连接失败"); + } + } +} + +void WebsocketClientForm::OnDisConnected(WebsocketClient* ws, WebsocketClient::CloseReason) +{ + std::cout << "OnDisConnected" << std::endl; +} + +void WebsocketClientForm::OnReadHandler(WebsocketClient* ws, std::string message) +{ + std::cout << "recv data from hanlder" << message.c_str(); +} diff --git a/examples/proto_debuger/websocket_client_form.h b/examples/proto_debuger/websocket_client_form.h index 9c8ef059..45e5e0df 100644 --- a/examples/proto_debuger/websocket_client_form.h +++ b/examples/proto_debuger/websocket_client_form.h @@ -26,6 +26,9 @@ public: virtual void Init() override; LuaDelegate* LuaVM(); void ShowDataInEdit(const char*); + void OnConnected(WebsocketClient*); + void OnDisConnected(WebsocketClient*, WebsocketClient::CloseReason); + void OnReadHandler(WebsocketClient*, std::string); private: ui::Label* m_label_1; ui::RichEdit* m_rich_edit_1;