Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
489 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 Reply

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...