no message

master
zcy 2021-08-31 22:23:45 +08:00
parent b2cab52f89
commit 7de228601d
4 changed files with 15 additions and 4 deletions

View File

@ -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);

View File

@ -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()<<datagram.data().length();
ret.len = datagram.data().length();
}
}
else{
memcpy(data,mCnn->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());
}

View File

@ -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()<<ret.len<<ret.addr;
if(ret.len > 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()<<dat;

View File

@ -60,6 +60,7 @@ public slots:
void on_network_data_recv();
void on_network_conected();
void on_network_disconected();
void on_udp_data_recv();
private:
NetworkController *m_network_;