我的网络中有2个节点,它们之间的通信使用UDPBaiscApp。Node 1定期向node 2发送长度为10kb的报文,现在我想对Node 1拥有的数据大小进行限制。例如,如果节点1具有100kB的数据,并且它一次发送10kB,则在发送消息10次之后,通信应当结束。那么如何分配Node1可以拥有最大数据呢?
发布于 2016-02-04 07:18:19
您可以通过多种方式来完成此操作,例如这样:
1)在类UDPBasicApp定义中增加两个变量:
long alreadySentBytes;
long limitBytes;2)在UDPBasicApp::initialise() fill initial中:
alreadySentBytes = 0;
limitBytes = 100 * 1024; // 100KB3)在UDPBasicApp::sendPacket()中做如下修改:
void UDPBasicApp::sendPacket()
{
if (alreadySentBytes < limitBytes) {
std::ostringstream str;
str << packetName << "-" << numSent;
cPacket *payload = new cPacket(str.str().c_str());
payload->setByteLength(par("messageLength").longValue());
alreadySentBytes += par("messageLength").longValue();
L3Address destAddr = chooseDestAddr();
emit(sentPkSignal, payload);
socket.sendTo(payload, destAddr, destPort);
numSent++;
}
}https://stackoverflow.com/questions/35179232
复制相似问题