Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have to send the same message to multiple modules. I used the following code:

cMessage *msg=new cMessage("Broadcast");
msg->setKind(SENDTOALL);

cTopology topo;
topo.extractByModulePath(cStringTokenizer("**.router*.app[0]").asVector());

cTopology::Node *thisNode = topo.getNodeFor(this);

for (int i = 0; i < topo.getNumNodes(); i++) {
if (topo.getNode(i) == thisNode) continue; // skip ourselves


cModule *targetModule =topo.getNode(i)->getModule();

EV_INFO  << "Get Full Name ------------------- "<<i<< topo.getNode(i)->getModule()->getFullPath()<<endl;

sendDirect(msg,targetModule,"in");

after sending the message to the first module and trying to send to the next module, I get the following error that the message already scheduled and the simulation stops at this point.

enter image description here

Can I get any advice? I will be really thankful.

Thank you in advance.

question from:https://stackoverflow.com/questions/65879799/i-get-an-error-when-trying-to-send-to-multiple-modules-using-senddirect

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
481 views
Welcome To Ask or Share your Answers For Others

1 Answer

The message cannot be sent more than once. To send the same message to many modules, every time copy of this message must be created. dup() is the convenient method to make a copy, for example:

cMessage *copyMsg = msg->dup();
sendDirect(copyMsg ,targetModule,"in");

Reference: Simulation Manual - Broadcasting messages


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...