2021-12-30 17:27:33 +08:00
|
|
|
|
#include "tcp_server_form.h"
|
2021-12-31 15:35:46 +08:00
|
|
|
|
#include "utils.h"
|
2022-01-06 00:31:24 +08:00
|
|
|
|
#include <functional>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
|
#include "event2/bufferevent.h"
|
|
|
|
|
#include "event2/buffer.h"
|
|
|
|
|
#include "event2/listener.h"
|
|
|
|
|
#include "event2/util.h"
|
|
|
|
|
#include "event2/event.h"
|
|
|
|
|
#include "event2/thread.h"
|
|
|
|
|
};
|
|
|
|
|
|
2021-12-30 17:27:33 +08:00
|
|
|
|
|
|
|
|
|
TcpServerFrom::TcpServerFrom(ui::Window* hwnd, string url, uint32_t port, TcpServerLibevent* p)
|
|
|
|
|
{
|
2021-12-31 01:12:11 +08:00
|
|
|
|
m_server = p;
|
|
|
|
|
m_url = url;
|
|
|
|
|
m_port = port;
|
|
|
|
|
|
2022-01-05 01:41:58 +08:00
|
|
|
|
|
2022-01-06 00:31:24 +08:00
|
|
|
|
TcpServerLibevent::OnAccept handler = std::bind(&TcpServerFrom::OnNewConnAccept, this,std::placeholders::_1 ,
|
|
|
|
|
std::placeholders::_2, std::placeholders::_3 );
|
|
|
|
|
m_server->SetNewConnectionHandle(handler);
|
|
|
|
|
TcpServerLibevent::OnDisconnect handler2 = std::bind(&TcpServerFrom::OnDisConnected,
|
|
|
|
|
this, std::placeholders::_1);
|
|
|
|
|
m_server->SetConnectionLeaveHandle(handler2);
|
|
|
|
|
|
2021-12-30 17:27:33 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TcpServerLibevent* TcpServerFrom::ServerP()
|
|
|
|
|
{
|
|
|
|
|
return this->m_server;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TcpServerFrom::Init()
|
|
|
|
|
{
|
|
|
|
|
ui::ChildBox::Init(); // <20>dz<EFBFBD><C7B3><EFBFBD>Ҫ,û<><C3BB><EFBFBD>º<EFBFBD>childbox <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>FindSubControl<6F><EFBFBD><DEB7><EFBFBD>Ч
|
2022-01-06 00:31:24 +08:00
|
|
|
|
|
|
|
|
|
m_label_1 = dynamic_cast<ui::Label*>(FindSubControl(L"server_info"));
|
|
|
|
|
m_rich_edit_1 = dynamic_cast<ui::RichEdit*>(FindSubControl(L"server_recv_edit"));
|
|
|
|
|
m_rich_edit_2 = dynamic_cast<ui::RichEdit*>(FindSubControl(L"lua_script_edit"));
|
|
|
|
|
m_rich_edit_3 = dynamic_cast<ui::RichEdit*>(FindSubControl(L"server_send_edit"));
|
|
|
|
|
m_button_1 = dynamic_cast<ui::Button*>(FindSubControl(L"btn_send_data"));
|
|
|
|
|
m_check_box_2 = dynamic_cast<ui::CheckBox*>(FindSubControl(L"check_time_send"));
|
|
|
|
|
m_rich_edit_4 = dynamic_cast<ui::RichEdit*>(FindSubControl(L"cycle_eidt"));
|
|
|
|
|
m_check_box_3 = dynamic_cast<ui::CheckBox*>(FindSubControl(L"check_hex_send"));
|
|
|
|
|
m_check_box_4 = dynamic_cast<ui::CheckBox*>(FindSubControl(L"check_hex_recv"));
|
|
|
|
|
m_button_2 = dynamic_cast<ui::Button*>(FindSubControl(L"btn_close_uart"));
|
|
|
|
|
m_label_2 = dynamic_cast<ui::Label*>(FindSubControl(L"title"));
|
|
|
|
|
m_combo_1 = dynamic_cast<ui::Combo*>(FindSubControl(L"clients"));
|
|
|
|
|
m_button_3 = dynamic_cast<ui::Button*>(FindSubControl(L"btn_do_lua"));
|
2021-12-30 17:27:33 +08:00
|
|
|
|
|
2021-12-31 15:35:46 +08:00
|
|
|
|
wchar_t p[200] = L"";
|
|
|
|
|
wsprintf(p,L"<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ: %s <20>˿<EFBFBD>: %d <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ: %d",string2wstring(m_url).c_str(),
|
|
|
|
|
m_port,
|
|
|
|
|
m_server->ConnectionCount());
|
|
|
|
|
m_label_1->SetText(p);
|
2021-12-30 17:27:33 +08:00
|
|
|
|
}
|
2022-01-05 01:41:58 +08:00
|
|
|
|
|
2022-01-06 00:31:24 +08:00
|
|
|
|
ConnectionLibevent* TcpServerFrom::OnNewConnAccept(struct bufferevent* ev, uint32_t fd, struct sockaddr_in* p1)
|
|
|
|
|
{
|
|
|
|
|
std::cout << "TcpServerFrom OnNewConnAccept fd" << fd << " addr " << inet_ntoa(p1->sin_addr)<<std::endl;
|
|
|
|
|
|
|
|
|
|
wchar_t text[40] = L"";
|
|
|
|
|
wsprintf(text, L"<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:%d", m_server->ConnectionCount());
|
|
|
|
|
m_label_1->SetText(text);
|
|
|
|
|
return new ConnectionLibevent(ev, fd, p1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TcpServerFrom::OnDisConnected(ConnectionLibevent* cli)
|
2022-01-05 01:41:58 +08:00
|
|
|
|
{
|
2022-01-06 00:31:24 +08:00
|
|
|
|
std::cout << "TcpServerFrom Disconnected" << cli->IpAddress() << " fd " << cli->SocketFd() << std::endl;
|
2022-01-05 01:41:58 +08:00
|
|
|
|
|
|
|
|
|
}
|