add udp implement
This commit is contained in:
parent
fa11185174
commit
02a2780678
@ -174,6 +174,7 @@
|
|||||||
<ClCompile Include="tcp_client_form.cpp" />
|
<ClCompile Include="tcp_client_form.cpp" />
|
||||||
<ClCompile Include="tcp_server_libevent.cpp" />
|
<ClCompile Include="tcp_server_libevent.cpp" />
|
||||||
<ClCompile Include="uart_form.cpp" />
|
<ClCompile Include="uart_form.cpp" />
|
||||||
|
<ClCompile Include="udp_client_libevent.cpp" />
|
||||||
<ClCompile Include="utils.cpp" />
|
<ClCompile Include="utils.cpp" />
|
||||||
<ClCompile Include="lua_bind.cpp" />
|
<ClCompile Include="lua_bind.cpp" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
@ -190,6 +191,7 @@
|
|||||||
<ClInclude Include="tcp_server_form.h" />
|
<ClInclude Include="tcp_server_form.h" />
|
||||||
<ClInclude Include="tcp_client_form.h" />
|
<ClInclude Include="tcp_client_form.h" />
|
||||||
<ClInclude Include="uart_process.h" />
|
<ClInclude Include="uart_process.h" />
|
||||||
|
<ClInclude Include="udp_client_libevent.h" />
|
||||||
<ClInclude Include="utils.h" />
|
<ClInclude Include="utils.h" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
@ -57,6 +57,9 @@
|
|||||||
<ClCompile Include="global.cpp">
|
<ClCompile Include="global.cpp">
|
||||||
<Filter>源文件</Filter>
|
<Filter>源文件</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="udp_client_libevent.cpp">
|
||||||
|
<Filter>源文件</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="main.h">
|
<ClInclude Include="main.h">
|
||||||
@ -98,6 +101,9 @@
|
|||||||
<ClInclude Include="global.h">
|
<ClInclude Include="global.h">
|
||||||
<Filter>头文件</Filter>
|
<Filter>头文件</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="udp_client_libevent.h">
|
||||||
|
<Filter>头文件</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Xml Include="..\Debug\resources\themes\default\basic\basic.xml">
|
<Xml Include="..\Debug\resources\themes\default\basic\basic.xml">
|
||||||
|
@ -1 +1 @@
|
|||||||
require("string")
function OnNewClient(ip,port)
showdata("on new client from lua " .. ip..port.."32232323\r\n")
end
function OnClientRecvData(data)
showdata("client recieve data from lua "..data.."\r\n")
end
function OnClientDisconnect(ip,port)
showdata("client leave from lua " .. ip..port)
end
|
require("string")
function OnNewClient(ip,port)
showdata("on new client from lua " .. ip..port.."32232323\r\n")
end
function OnClientRecvData(data)
showdata("client recieve data from lua "..data.."+++12312312\r\n")
end
function OnClientDisconnect(ip,port)
showdata("client leave from lua " .. ip..port)
end
|
@ -47,24 +47,20 @@ void TcpClientForm::ShowDataInEdit(const char*p) {
|
|||||||
void TcpClientForm::Init()
|
void TcpClientForm::Init()
|
||||||
{
|
{
|
||||||
ui::ChildBox::Init();
|
ui::ChildBox::Init();
|
||||||
|
|
||||||
m_label_1 = dynamic_cast<ui::Label*>(FindSubControl(L"uart_info_label"));
|
m_label_1 = dynamic_cast<ui::Label*>(FindSubControl(L"uart_info_label"));
|
||||||
m_rich_edit_1 = dynamic_cast<ui::RichEdit*>(FindSubControl(L"uart_recv_eidt"));
|
m_rich_edit_1 = dynamic_cast<ui::RichEdit*>(FindSubControl(L"uart_recv_eidt"));
|
||||||
m_rich_edit_2 = dynamic_cast<ui::RichEdit*>(FindSubControl(L"lua_script"));
|
m_rich_edit_2 = dynamic_cast<ui::RichEdit*>(FindSubControl(L"lua_script"));
|
||||||
m_uart_send_edit = dynamic_cast<ui::RichEdit*>(FindSubControl(L"uart_send_edit"));
|
m_uart_send_edit = dynamic_cast<ui::RichEdit*>(FindSubControl(L"uart_send_edit"));
|
||||||
m_btn_send_data = dynamic_cast<ui::Button*>(FindSubControl(L"btn_send_data"));
|
m_btn_send_data = dynamic_cast<ui::Button*>(FindSubControl(L"btn_send_data"));
|
||||||
m_check_box_1 = dynamic_cast<ui::CheckBox*>(FindSubControl(L"check_new_line"));
|
|
||||||
m_check_box_2 = dynamic_cast<ui::CheckBox*>(FindSubControl(L"check_time_send"));
|
m_check_box_2 = dynamic_cast<ui::CheckBox*>(FindSubControl(L"check_time_send"));
|
||||||
m_check_box_3 = dynamic_cast<ui::CheckBox*>(FindSubControl(L"check_hex_send"));
|
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_check_box_4 = dynamic_cast<ui::CheckBox*>(FindSubControl(L"check_hex_recv"));
|
||||||
m_btn_save_lua = dynamic_cast<ui::Button*>(FindSubControl(L"btn_save_lua"));
|
m_btn_save_lua = dynamic_cast<ui::Button*>(FindSubControl(L"btn_save_lua"));
|
||||||
|
|
||||||
|
|
||||||
m_rich_edit_2->SetRich(true);
|
m_rich_edit_2->SetRich(true);
|
||||||
m_rich_edit_2->SetReturnMsgWantCtrl(true);
|
m_rich_edit_2->SetReturnMsgWantCtrl(true);
|
||||||
m_rich_edit_2->SetText(string2wstring(mLuaScript));
|
m_rich_edit_2->SetText(string2wstring(mLuaScript));
|
||||||
|
|
||||||
|
|
||||||
wchar_t p[100] = { 0 };
|
wchar_t p[100] = { 0 };
|
||||||
wsprintf(p, L"地址%s,端口号%d 未连接", string2wstring(m_url).c_str(),m_port);
|
wsprintf(p, L"地址%s,端口号%d 未连接", string2wstring(m_url).c_str(),m_port);
|
||||||
m_label_1->SetText(std::wstring(p));
|
m_label_1->SetText(std::wstring(p));
|
||||||
@ -73,13 +69,12 @@ void TcpClientForm::Init()
|
|||||||
if (ev->Type == ui::EventType::kEventClick) {
|
if (ev->Type == ui::EventType::kEventClick) {
|
||||||
std::wcout << m_uart_send_edit->GetText() << std::endl;
|
std::wcout << m_uart_send_edit->GetText() << std::endl;
|
||||||
auto data = wstring2string(m_uart_send_edit->GetText());
|
auto data = wstring2string(m_uart_send_edit->GetText());
|
||||||
if (m_check_box_1->IsSelected()) {
|
data += std::string("\r\n");
|
||||||
data += std::string("\r\n");
|
|
||||||
}
|
|
||||||
this->ClientEvent()->SendDataAsync(data.c_str(), data.size());
|
this->ClientEvent()->SendDataAsync(data.c_str(), data.size());
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (nullptr != m_btn_save_lua) {
|
if (nullptr != m_btn_save_lua) {
|
||||||
m_btn_save_lua->AttachClick([this](ui::EventArgs*) {
|
m_btn_save_lua->AttachClick([this](ui::EventArgs*) {
|
||||||
std::cout << "保存lua脚本\r\n";
|
std::cout << "保存lua脚本\r\n";
|
||||||
|
@ -93,7 +93,6 @@ private:
|
|||||||
OnAccept m_handle_accept;
|
OnAccept m_handle_accept;
|
||||||
OnDisconnect m_handle_disconnect;
|
OnDisconnect m_handle_disconnect;
|
||||||
intptr_t mSocketFD; // 操作系统原生socket
|
intptr_t mSocketFD; // 操作系统原生socket
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
8
examples/proto_debuger/udp_client_libevent.cpp
Normal file
8
examples/proto_debuger/udp_client_libevent.cpp
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
#include "udp_client_libevent.h"
|
||||||
|
|
||||||
|
UdpClientLibevent::UdpClientLibevent(std::string ipaddr, uint32_t port)
|
||||||
|
{
|
||||||
|
this->m_bind_ip = ipaddr;
|
||||||
|
this->m_port = m_port;
|
||||||
|
|
||||||
|
}
|
36
examples/proto_debuger/udp_client_libevent.h
Normal file
36
examples/proto_debuger/udp_client_libevent.h
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifndef _WIN32_WINNT
|
||||||
|
#define _WIN32_WINNT 0x0500
|
||||||
|
#include <WinSock2.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef linux
|
||||||
|
#include<sys/types.h>
|
||||||
|
#include<sys/socket.h>
|
||||||
|
#include<arpa/inet.h>
|
||||||
|
#define EVENT__HAVE_PTHREADS
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include <mutex>
|
||||||
|
#include <thread>
|
||||||
|
#include <map>
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
class UdpClientLibevent
|
||||||
|
{
|
||||||
|
UdpClientLibevent(std::string ipaddr,uint32_t port);
|
||||||
|
|
||||||
|
private:
|
||||||
|
uint32_t m_port; // 监听端口号
|
||||||
|
string m_bind_ip; // 绑定端口号
|
||||||
|
int m_current_conection; // 当前连接数目
|
||||||
|
uint16_t m_backlog;
|
||||||
|
struct sockaddr_in m_server_addr; // 服务器地址
|
||||||
|
struct event_base* m_event_base;
|
||||||
|
};
|
||||||
|
|
Loading…
Reference in New Issue
Block a user