From 7de228601de07c51d5ee6307af6ff62197255441 Mon Sep 17 00:00:00 2001 From: zcy <290198252@qq.com> Date: Tue, 31 Aug 2021 22:23:45 +0800 Subject: [PATCH] no message --- protoDebuger/lua_wraper.cpp | 1 + protoDebuger/network_controller.cpp | 8 ++++---- protoDebuger/sharedata.cpp | 9 +++++++++ protoDebuger/sharedata.h | 1 + 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/protoDebuger/lua_wraper.cpp b/protoDebuger/lua_wraper.cpp index 235026b..324cf5c 100644 --- a/protoDebuger/lua_wraper.cpp +++ b/protoDebuger/lua_wraper.cpp @@ -31,6 +31,7 @@ void LuaDelegate::OnSerialData(QString data){ void LuaDelegate::OnNetworkData(char *addr, char *data, uint32_t port) { + qDebug()<<"call lua network callback"; int ret = lua_getglobal(mVM,"OnNetworkData"); lua_pushstring(mVM,addr); lua_pushstring(mVM,data); diff --git a/protoDebuger/network_controller.cpp b/protoDebuger/network_controller.cpp index f11a635..db0cc3b 100644 --- a/protoDebuger/network_controller.cpp +++ b/protoDebuger/network_controller.cpp @@ -77,17 +77,18 @@ NetworkController::RecvResult NetworkController::ReadData(int8_t *data) } if((mType == TYPE_UDP_CLIENT )||(mType == TYPE_UDP_SERVER)){ int len = 0; - while(mUDP->hasPendingDatagrams()){ + if(mUDP->hasPendingDatagrams()){ QNetworkDatagram datagram = mUDP->receiveDatagram(); - memcpy(data + len,datagram.data().data(),datagram.data().size()); + memcpy(data,datagram.data().data(),datagram.data().size()); len += datagram.data().size(); ret.addr = datagram.senderAddress().toString(); ret.port = datagram.senderPort(); - qDebug()<readAll().data(),mCnn->size()); + ret.len = mCnn->size(); } return ret; } @@ -153,7 +154,6 @@ void NetworkController::tcpsock_stateChanged(QAbstractSocket::SocketState state) void NetworkController::on_ready_read() { - qDebug()<<"data read:"; emit(on_data_recv()); } diff --git a/protoDebuger/sharedata.cpp b/protoDebuger/sharedata.cpp index 6247e3a..440b7a6 100644 --- a/protoDebuger/sharedata.cpp +++ b/protoDebuger/sharedata.cpp @@ -181,6 +181,15 @@ bool QmlShareData::luaStatus() void QmlShareData::on_network_data_recv(){ qDebug()<<"recv data"; + char dat[4096] = {0}; + auto ret = this->m_network_->ReadData((int8_t * )dat); + qDebug()< 0){ + m_lua_.OnNetworkData((char*)ret.addr.toStdString().data(),dat,ret.port.toUInt()); + } +} + +void QmlShareData::on_udp_data_recv(){ char dat[4096] = {0}; auto ret = this->m_network_->ReadData((int8_t * )dat); qDebug()<