diff --git a/examples/proto_debuger/base_form.cpp b/examples/proto_debuger/base_form.cpp index ce0a37b8..2623e9ee 100644 --- a/examples/proto_debuger/base_form.cpp +++ b/examples/proto_debuger/base_form.cpp @@ -198,6 +198,7 @@ LRESULT BasicForm::HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam) }); mMonitorNewSelect->Close(); } + if (uMsg == WM_ADD_WEBSOCKET_CLIENT) { TcpServerInfo* info = (TcpServerInfo*)wParam; ui::TreeNode* node = new ui::TreeNode; @@ -279,7 +280,6 @@ LRESULT BasicForm::HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam) if (p != nullptr) { printf("GetCurSel %d\r\n", mRightSide->GetCurSel()); - p->SetAutoDestroy(true); if (mRightShow != nullptr) { mRightShow->SetVisible(false); diff --git a/examples/proto_debuger/new_monitor_form.cpp b/examples/proto_debuger/new_monitor_form.cpp index fc57589b..97a09b91 100644 --- a/examples/proto_debuger/new_monitor_form.cpp +++ b/examples/proto_debuger/new_monitor_form.cpp @@ -211,7 +211,7 @@ void NewMonitorForm::InitWindow() if (m_combo_type->GetText() == L"websocket client") { wprintf(L"%s\r\n", m_ip_select->GetText().c_str()); wprintf(L"%s\r\n", m_port_select->GetText().c_str()); - WebsocketClient* wsclient = new WebsocketClient(wstring2string(m_ip_select->GetText().c_str()),false); + WebsocketClient* wsclient = new WebsocketClient(wstring2string(m_ip_select->GetText().c_str()),true); TcpServerInfo* p = new TcpServerInfo; p->ip = m_ip_select->GetText(); diff --git a/examples/proto_debuger/websocket_client.cpp b/examples/proto_debuger/websocket_client.cpp index 757eb177..7c89ca15 100644 --- a/examples/proto_debuger/websocket_client.cpp +++ b/examples/proto_debuger/websocket_client.cpp @@ -98,6 +98,10 @@ WebsocketClient::~WebsocketClient() { m_thread->join(); } +std::string WebsocketClient::Url() +{ + return this->m_url; +} WebsocketClient::WebsocketClient(std::string url, bool tls) { m_tls = tls; @@ -140,9 +144,9 @@ WebsocketClient::WebsocketClient(std::string url, bool tls) if (ec) { std::cout << "could not create connection because: " << ec.message() << std::endl; this->m_status = Status::FAIL; + break; } std::cout << "2" << std::endl; - // Note that connect here only requests a connection. No network messages are // exchanged until the event loop starts running in the next line. TlsClient::connection_ptr ptr = m_client_tls.connect(m_conn_tls); @@ -158,9 +162,7 @@ WebsocketClient::WebsocketClient(std::string url, bool tls) && (this->m_status != WebsocketClient::STOP) ) { try { - // while(this->m_status == WebsocketClient::CONNECTED){ int count_of_handler = this->m_client_tls.run(); - // std::cout<<"count_of_handler: " << count_of_handler<m_status = Status::FAIL; if (m_on_disconnected) - m_on_disconnected(this, WebsocketClient::CloseReason::LOCAL_CLOSED); + m_on_disconnected(this, + WebsocketClient::CloseReason::LOCAL_CLOSED); break; } - std::cout << "2" << std::endl; // Note that connect here only requests a connection. No network messages are // exchanged until the event loop starts running in the next line. @@ -228,7 +230,8 @@ WebsocketClient::WebsocketClient(std::string url, bool tls) while ((this->m_status != WebsocketClient::FAIL) && (this->m_status != WebsocketClient::CLOSED) && (this->m_status != WebsocketClient::STOP) - ) { + ) + { try { // while(this->m_status == WebsocketClient::CONNECTED){ int count_of_handler = this->m_client.run(); diff --git a/examples/proto_debuger/websocket_client.h b/examples/proto_debuger/websocket_client.h index 9050e68f..c0f357be 100644 --- a/examples/proto_debuger/websocket_client.h +++ b/examples/proto_debuger/websocket_client.h @@ -49,6 +49,7 @@ public: Status State(){ return m_status; } + std::string Url(); WebsocketClient(std::string url,bool tls); ~WebsocketClient(); int SendMsg(const char * str,uint32_t len,websocketpp::frame::opcode::value); diff --git a/examples/proto_debuger/websocket_client_form.cpp b/examples/proto_debuger/websocket_client_form.cpp index 524b1a29..2e91ceb4 100644 --- a/examples/proto_debuger/websocket_client_form.cpp +++ b/examples/proto_debuger/websocket_client_form.cpp @@ -17,7 +17,7 @@ WebsocketClientForm::~WebsocketClientForm() void WebsocketClientForm::Init() { ui::ChildBox::Init(); - m_label_1 = dynamic_cast(FindSubControl(L"uart_info_label")); + m_label_1 = dynamic_cast(FindSubControl(L"server_info")); m_rich_edit_1 = dynamic_cast(FindSubControl(L"uart_recv_eidt")); m_rich_edit_2 = dynamic_cast(FindSubControl(L"lua_script")); m_uart_send_edit = dynamic_cast(FindSubControl(L"uart_send_edit")); @@ -28,9 +28,22 @@ void WebsocketClientForm::Init() m_btn_save_lua = dynamic_cast(FindSubControl(L"btn_save_lua")); m_btn_close_form = dynamic_cast(FindSubControl(L"btn_close_uart")); + 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"ʧ"); + } + } if (nullptr != m_btn_close_form) m_btn_close_form->AttachClick([this](const ui::EventArgs* ev) { - + wstring* name = new wstring(this->GetName()); + ::PostMessage(this->GetWindow()->GetHWND(), + WM_ADD_WEBSOCKET_CLIENT_CLOSE, (WPARAM)name, 0); return true; } ); @@ -42,6 +55,7 @@ void WebsocketClientForm::Init() return true; } ); + if (nullptr != m_btn_send_data) { m_btn_send_data->AttachClick([this](const ui::EventArgs* ev) {