diff --git a/examples/proto_debuger/udp_form.cpp b/examples/proto_debuger/udp_form.cpp index 7f145bc4..942c0269 100644 --- a/examples/proto_debuger/udp_form.cpp +++ b/examples/proto_debuger/udp_form.cpp @@ -25,16 +25,19 @@ UdpForm::UdpForm(ui::Window* hwnd, string url, uint32_t port, UdpDataGramLibeven mLuaScript = lua_script; mLua->DoString(lua_script); - UdpDataGramLibevent::OnReadDataHandle onRecvCallBack([this](const char* dat, int len, struct sockaddr_in sendarr){ - //this->LuaVM()->CallFuntion(); + UdpDataGramLibevent::OnReadDataHandle onRecvCallBack + = [this](const char* dat, int len, struct sockaddr_in sendarr){ + std::cout << "receive udp datagram len" << len << dat << "\r\n"; + this->mLua->CallFuntion("OnUdpData", std::string(dat), inet_ntoa(sendarr.sin_addr),sendarr.sin_port); - }); + + }; if (mUdpPeer != nullptr) { - mUdpPeer->SetOnReadHandle(&onRecvCallBack); + std::cout << "\r\n"<< &onRecvCallBack <<"\r\n"; + mUdpPeer->SetOnReadHandle(onRecvCallBack); } this->mLua->BindFunction("showdata", LuaShowData); - std::cout << "lua script is " << lua_script << std::endl; } @@ -129,9 +132,10 @@ LuaDelegate* UdpForm::LuaVM() return mLua; } -void UdpForm::ShowDataInEdit(const char*) +void UdpForm::ShowDataInEdit(const char*src) { - + std::cout << src << " from ShowDataInEdit"; + this->m_rich_edit_1->AppendText(string2wstring(std::string(src))); } void UdpForm::HandleMessage(ui::EventArgs& msg) diff --git a/examples/proto_debuger/udp_form.h b/examples/proto_debuger/udp_form.h index d76ec126..af92894e 100644 --- a/examples/proto_debuger/udp_form.h +++ b/examples/proto_debuger/udp_form.h @@ -23,7 +23,8 @@ #include class UdpForm : - public ui::ChildBox + public ui::ChildBox, + LuaBindInterface { public: diff --git a/examples/proto_debuger/udp_libevent.cpp b/examples/proto_debuger/udp_libevent.cpp index ded555b3..f8f4bbcd 100644 --- a/examples/proto_debuger/udp_libevent.cpp +++ b/examples/proto_debuger/udp_libevent.cpp @@ -39,7 +39,9 @@ void read_cb(evutil_socket_t fd, short event, void* arg) { printf("recv[%s:%d]\n", buf, len); // sendto(fd, buf, len, 0, (struct sockaddr*)&cli_addr, addr_len); if (parent->OnReadHandle() != nullptr) { - (*parent->OnReadHandle())(buf, len, cli_addr); + UdpDataGramLibevent::OnReadDataHandle p = (parent->OnReadHandle()); + if(p) + p(buf, len, cli_addr); } } } @@ -82,11 +84,11 @@ int UdpDataGramLibevent::bind_socket(struct event* ev, const char* ip, uint16_t return 0; } -UdpDataGramLibevent::OnReadDataHandle* UdpDataGramLibevent::OnReadHandle() { +UdpDataGramLibevent::OnReadDataHandle UdpDataGramLibevent::OnReadHandle() { return this->mOnRead; } -void UdpDataGramLibevent::SetOnReadHandle(UdpDataGramLibevent::OnReadDataHandle* p) { +void UdpDataGramLibevent::SetOnReadHandle(UdpDataGramLibevent::OnReadDataHandle p) { this->mOnRead = p; } diff --git a/examples/proto_debuger/udp_libevent.h b/examples/proto_debuger/udp_libevent.h index a0e3d382..0d5de848 100644 --- a/examples/proto_debuger/udp_libevent.h +++ b/examples/proto_debuger/udp_libevent.h @@ -26,14 +26,14 @@ class UdpDataGramLibevent { public: typedef std::function OnReadDataHandle; UdpDataGramLibevent(std::string ip, uint32_t port); - OnReadDataHandle* OnReadHandle(); + OnReadDataHandle OnReadHandle(); typedef enum { RUNNING, STOP, FAIL }STATUS; friend void read_cb(int, short, void*); - void SetOnReadHandle(OnReadDataHandle*); + void SetOnReadHandle(OnReadDataHandle); void SendTo(const char* dat, uint32_t len, std::string ip, int port); int SocketFD(); private: @@ -47,7 +47,7 @@ private: STATUS m_status; // std::thread* m_thread; // 当前线程 intptr_t mSocketFD; // 操作系统原生socket - OnReadDataHandle* mOnRead; + OnReadDataHandle mOnRead; };