1 Star 1 Fork 4

MageeLow/packet_analyzer

forked from biiigfish/packet_analyzer 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
myUDP.cpp 1.35 KB
一键复制 编辑 原始数据 按行查看 历史
#include "myUDP.h"
#include <QTimer>
myUDP::myUDP()
{
qDebug()<<"hi";
ready2send = false;
packet_testing = false;
udpSocket = new QUdpSocket(this);
udpSocket->bind(QHostAddress("127.0.0.1"), 2000);
//udpSocket->bind(2000);
connect(udpSocket, SIGNAL(readyRead()),this, SLOT(readCmd()));
// QTimer *taskTimer = new QTimer;
// taskTimer->start(200);
// connect(taskTimer, SIGNAL(timeout()), this, SLOT(sendResult()));
}
myUDP::~myUDP()
{
qDebug()<<"bye";
}
void myUDP::run()
{
exec();
}
void myUDP::sendResult(char* buff, int size)
{
QHostAddress hostaddr;
hostaddr.setAddress( "127.0.0.1" );
udpSocket->writeDatagram(buff, size, hostaddr, 1999);
// if(ready2send)
// {
// udpSocket->writeDatagram( sendBuf, hostaddr, 1999);
// ready2send = false;
// sendBuf.resize(0);
// }
//qDebug()<<"taskTimer";
}
void myUDP::readCmd()
{
qDebug()<<"new coming!";
QByteArray rcvd;
if( udpSocket->hasPendingDatagrams() )
{
rcvd.resize(udpSocket->pendingDatagramSize());
udpSocket->readDatagram(rcvd.data(), rcvd.size());
}
char *ch = rcvd.data();
if( memcmp(ch, "start", 5) == 0 )
{
packet_testing = true;
}
if( memcmp(ch, "stop", 4) == 0 )
{
packet_testing = false;
}
emit startOrStop(packet_testing);
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/1075504040/packet_analyzer.git
[email protected]:1075504040/packet_analyzer.git
1075504040
packet_analyzer
packet_analyzer
master

搜索帮助