no message

This commit is contained in:
zcy 2021-11-24 00:37:05 +08:00
parent 65771d0be6
commit 66ae5b8e0f
3 changed files with 13 additions and 8 deletions

View File

@ -31,6 +31,7 @@ std::wstring BasicForm::GetWindowClassName() const
return kClassName;
}
int gTcpClientCnt = 0;
LRESULT BasicForm::HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
{
if (uMsg == WM_ADD_UART_CLOSE) {
@ -72,21 +73,22 @@ LRESULT BasicForm::HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
TcpClientInfo* info = (TcpClientInfo*)wParam;
TcpClientLibevent* cli = (TcpClientLibevent*)lParam;
ui::TreeNode* node = new ui::TreeNode;
node->SetText(info->ip + L":" + std::to_wstring(info->socket_fd));
auto key = info->ip + L":" + std::to_wstring(gTcpClientCnt);
node->SetText(key);
node->SetTextId(L"sdfsdfasd");
node->SetClass(L"listitem");
node->SetFixedHeight(20);
node->SetMargin({ 20, 0, 0, 0 });
mMonitor->GetRootNode()->GetChildNode(1)->AddChildNode(node);
gTcpClientCnt++;
if (mTcpClientForm.find(info->ip + L":"
+ std::to_wstring(info->socket_fd)) == mTcpClientForm.end())
+ std::to_wstring(gTcpClientCnt)) == mTcpClientForm.end())
{
auto form = new TcpClientForm(this,wstring2string(info->ip),info->port, cli);
form->SetChildLayoutXML(L"basic/uart_form.xml");
form->SetName(info->ip + L":" + std::to_wstring(info->socket_fd));
form->SetChildLayoutXML(L"basic/tcp_form.xml");
form->SetName(key);
form->SetVisible(false);
mTcpClientForm[info->ip + L":" + std::to_wstring(info->socket_fd)] = form;
mTcpClientForm[key] = form;
if (!mRightSide->Add(form))
printf("erroer 1");
}

View File

@ -55,11 +55,10 @@ void conn_readcb(struct bufferevent *bev, void *user_data)
{
uint8_t *msg = new uint8_t[sz];
int ret = bufferevent_read(bev, msg, sz);
msg[ret - 1] = '\0';
printf("%s\n", msg);
if(server->mObserver != nullptr){
server->mObserver->OnData(msg, ret);
}
server->mObserver->OnData(msg,ret);
delete[] msg;
}
}
@ -87,6 +86,7 @@ void conn_eventcb(struct bufferevent *bev, short events, void *user_data)
else if (events & BEV_EVENT_CONNECTED) {
p->mSocketFD = (uint64_t)event_get_fd(&(bev->ev_read));
//客户端链接成功后,给服务器发送第一条消息
std::cout << "socket fd" << p->mSocketFD;
if (nullptr != p->mObserver)
p->mObserver->OnConnected();
p->mStatus = TcpClientLibevent::CONNECTED;

View File

@ -36,6 +36,9 @@ void TcpClientForm::Init()
if (ev->Type == ui::EventType::kEventClick) {
std::wcout << m_uart_send_edit->GetText() << std::endl;
auto data = wstring2string(m_uart_send_edit->GetText());
if (m_check_box_1->IsSelected()) {
data += std::string("\r\n");
}
this->ClientEvent()->SendDataAsync(data.c_str(), data.size());
}
return true;