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

Categories

0 votes
538 views
in Technique[技术] by (71.8m points)

omnet++ - I get an error when trying to send to multiple modules using sendDirect

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

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

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...