⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 groupsend.cpp

📁 本文件是<精通QT4编程>的配套源代码
💻 CPP
字号:
#include "GroupSend.h"GroupSend::GroupSend(){	count = 0;	FSendBuffer = (char*)malloc(sizeof(long)+1024*16);	memcpy(FSendBuffer, &count,sizeof(long));	timer = new QTimer(this);	connect(timer, SIGNAL(timeout()), this, SLOT(sendPakages()));	}GroupSend::~GroupSend(){	free(FSendBuffer);} void GroupSend::initSocket() {     	unsigned long  FSocket = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP);	unsigned char TTL = 16;	bool Loop = true;	setsockopt(FSocket, IPPROTO_IP, IP_MULTICAST_TTL, (const char *) &TTL,sizeof(unsigned char));	setsockopt(FSocket, IPPROTO_IP, IP_MULTICAST_LOOP, (const char *) &Loop,sizeof(unsigned char));	udpSocket = new QUdpSocket();		udpSocket->setSocketDescriptor(FSocket);	timer->start(1); } void GroupSend::sendPakages(){	qDebug()<<tr("packages sent:")<<count;	udpSocket->writeDatagram(FSendBuffer, sizeof(long)+1024*16, QHostAddress("225.1.0.111"),8999);	count++;	memcpy(FSendBuffer, &count,sizeof(long));}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -