diff --git a/protoDebuger/network_controller.cpp b/protoDebuger/network_controller.cpp index 4c79fea..46ab459 100644 --- a/protoDebuger/network_controller.cpp +++ b/protoDebuger/network_controller.cpp @@ -37,10 +37,11 @@ NetworkController::NetworkController(NetworkController::NetWorkType type, } if((type == NetWorkType::TYPE_UDP_SERVER) || (type == NetWorkType::TYPE_TCP_CLIENT)){ mUDP = new QUdpSocket(this); - mUDP->bind(QHostAddress::LocalHost, port); + mUDP->bind(QHostAddress::Any, port); mCnn = mUDP; connect(mUDP, SIGNAL(readyRead()), this, SLOT(on_ready_read())); + mUDP->open(QIODevice::ReadWrite); } } @@ -86,7 +87,12 @@ NetworkController::~NetworkController() void NetworkController::on_ready_read() { - qDebug()<readAll().toStdString()); + if((mType == TYPE_UDP_CLIENT )||(mType == TYPE_UDP_SERVER)){ + QNetworkDatagram datagram = mUDP->receiveDatagram(); + qDebug()<readAll().toStdString()); + } emit(on_data_recv()); } diff --git a/protoDebuger/network_controller.h b/protoDebuger/network_controller.h index 0a6e82d..0e38c2e 100644 --- a/protoDebuger/network_controller.h +++ b/protoDebuger/network_controller.h @@ -7,6 +7,7 @@ #include #include #include +#include // this is not a thread-safe class,any interface invoked in multi-thread maybe will cause unkown falut class NetworkController : public QObject diff --git a/protoDebuger/sharedata.cpp b/protoDebuger/sharedata.cpp index d104369..e6671ac 100644 --- a/protoDebuger/sharedata.cpp +++ b/protoDebuger/sharedata.cpp @@ -86,14 +86,15 @@ int ShareData::openNetwork(QString ip, unsigned int port, bool is_ws,int type) m_network_ = new NetworkController(NetworkController::TYPE_TCP_CLIENT,ip,port); return 0; } - if(type == NetworkController::TYPE_UDP_CLIENT){ - + if((type == NetworkController::TYPE_UDP_CLIENT) || + (type == NetworkController::TYPE_UDP_SERVER)){ + m_network_ = new NetworkController((NetworkController::NetWorkType)type,ip,port); + return 0; } if(type == NetworkController::TYPE_TCP_SERVER){ m_network_ = new NetworkController(NetworkController::TYPE_TCP_SERVER,ip,port); return 0; } - return -1; }