no message

This commit is contained in:
zcy 2022-03-09 17:12:36 +08:00
parent e915fb1447
commit 3a3887a763
3 changed files with 257 additions and 236 deletions

View File

@ -130,7 +130,6 @@ LRESULT BasicForm::HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
// delete mRightShow;
mRightShow = nullptr;
}
if (uMsg == WM_USER_TCP_SERVER_CLOSE) {
wprintf(L"close %s\r\n", ((wstring*)wParam)->c_str());
mRightShow->SetVisible(false);
@ -154,7 +153,6 @@ LRESULT BasicForm::HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
if (uMsg == WM_USER_POS_CHANGED) {
}
if (uMsg == WM_ADD_TCPCLIENT_MONITOR) {
TcpClientInfo* info = (TcpClientInfo*)wParam;
TcpClientLibevent* cli = (TcpClientLibevent*)lParam;
@ -212,7 +210,6 @@ LRESULT BasicForm::HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
if (mWebsocketClientForm.find(info->ip) == mWebsocketClientForm.end())
{
WebsocketClient* client = (WebsocketClient*)lParam;
auto form = new WebsocketClientForm(this, wstring2string(info->ip),client);
form->SetChildLayoutXML(L"basic/tcp_server_form.xml");
form->SetName(key);
@ -226,10 +223,28 @@ LRESULT BasicForm::HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
if (ui::EventType::kEventSelect == ev->Type) {
wprintf(L"%s\r\n", dynamic_cast<ui::TreeNode*> (ev->pSender)->GetText().c_str());
printf("GetCurSel %d\r\n", mRightSide->GetCurSel());
}
WebsocketClientForm* p = mWebsocketClientForm[dynamic_cast<ui::TreeNode*> (ev->pSender)->GetText()];
if (p != nullptr) {
printf("GetCurSel %d\r\n", mRightSide->GetCurSel());
p->SetAutoDestroy(true);
if (mRightShow != nullptr) {
mRightShow->SetVisible(false);
p->SetVisible(true);
mRightShow = p;
wprintf(L"%s", p->GetName());
mRightSide->SelectItem(p->GetName());
}
else {
wprintf(L"%s", p->GetName());
p->SetVisible(true);
mRightSide->SelectItem(p->GetName());
mRightShow = p;
}
}
return true;
}
);
}
if (uMsg == WM_ADD_TCPSERVER_MONITOR) {
TcpServerInfo* info = (TcpServerInfo*)wParam;
@ -427,7 +442,6 @@ LRESULT BasicForm::HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
}
else {
p->SetVisible(true);
mRightSide->SelectItem(p->GetName());
mRightShow = p;
}
@ -489,15 +503,12 @@ void BasicForm::InitWindow(){
node->SetFixedHeight(30);
mMonitor->GetRootNode()->AddChildNode(node);
node = new ui::TreeNode;
node->SetText(nbase::StringPrintf(L"udp group"));
node->SetClass(L"list_topitem");
node->SetFixedHeight(30);
mMonitor->GetRootNode()->AddChildNode(node);
node = new ui::TreeNode;
node->SetText(nbase::StringPrintf(L"websocket client"));
node->SetClass(L"list_topitem");

View File

@ -29,7 +29,8 @@ int WebsocketClient::SendMsg(const char * str,uint32_t len,
std::cout << "Echo failed because: " << ec.message() << std::endl;
return -1;
}
}else{
}
else {
websocketpp::lib::error_code ec;
this->m_client.send(m_conn, str, len, opcode, ec);
if (ec) {
@ -51,7 +52,8 @@ void on_open(WebsocketClient * c, websocketpp::connection_hdl hdl) {
if (c->m_on_connected != nullptr) {
c->m_on_connected(c);
}
}else{
}
else {
Client::connection_ptr con = c->m_client.get_con_from_hdl(hdl);
uint32_t usocket = con->get_raw_socket().native_handle();
auto m_server = con->get_response_header("Server");
@ -101,6 +103,8 @@ WebsocketClient::WebsocketClient(std::string url,bool tls)
m_tls = tls;
m_auto_reconn = false;
m_url = url;
this->m_status = WebsocketClient::CONNECTING;
if (m_tls) {
// Set logging to be pretty verbose (everything except message payloads)
m_client_tls.set_access_channels(websocketpp::log::alevel::all);
@ -159,7 +163,8 @@ WebsocketClient::WebsocketClient(std::string url,bool tls)
// std::cout<<"count_of_handler: " << count_of_handler<<std::endl;
// }
// run应该只执行一次就会退出
}catch(std::exception e){
}
catch (std::exception e) {
std::cout << "run exception" << e.what();
}
}
@ -184,6 +189,7 @@ WebsocketClient::WebsocketClient(std::string url,bool tls)
websocketpp::lib::error_code ec;
std::cout << "1" << std::endl;
m_conn = m_client.get_connection(this->m_url, ec);
if (m_conn != nullptr) {
m_conn->set_open_handler(websocketpp::lib::bind(
&on_open,
this,
@ -199,9 +205,13 @@ WebsocketClient::WebsocketClient(std::string url,bool tls)
this,
websocketpp::lib::placeholders::_1
));
}
if (ec) {
std::cout << "could not create connection because: " << ec.message() << std::endl;
this->m_status = Status::FAIL;
if (m_on_disconnected)
m_on_disconnected(this, WebsocketClient::CloseReason::LOCAL_CLOSED);
break;
}
std::cout << "2" << std::endl;
@ -225,15 +235,16 @@ WebsocketClient::WebsocketClient(std::string url,bool tls)
// std::cout<<"count_of_handler: " << count_of_handler<<std::endl;
// }
// run应该只执行一次就会退出
}catch(std::exception e){
}
catch (std::exception e) {
std::cout << "run exception" << e.what();
}
}
Sleep(1000);
}
std::cout << "close";
this->m_on_disconnected(this,WebsocketClient::CloseReason::LOCAL_CLOSED);
if(m_on_disconnected)
m_on_disconnected(this, WebsocketClient::CloseReason::LOCAL_CLOSED);
});
}

View File

@ -1,4 +1,5 @@
#include "websocket_client_form.h"
#include "utils.h"
WebsocketClientForm::WebsocketClientForm(ui::Window* hwnd, string url, WebsocketClient* p)
{
@ -30,14 +31,13 @@ void WebsocketClientForm::Init()
if (nullptr != m_btn_close_form)
m_btn_close_form->AttachClick([this](const ui::EventArgs* ev) {
return true;
}
);
if(nullptr != m_btn_save_lua)
m_btn_save_lua->AttachClick(
[this](ui::EventArgs* ev)
{
[this](ui::EventArgs* ev){
return true;
}
@ -47,7 +47,6 @@ void WebsocketClientForm::Init()
return true;
});
}
}
@ -58,5 +57,5 @@ LuaDelegate* WebsocketClientForm::LuaVM()
void WebsocketClientForm::ShowDataInEdit(const char*src)
{
m_rich_edit_1->AppendText(string2wstring(std::string(src)),false);
}