同时从所有节点发送消息 [英] send messages from all nodes at the same time
问题描述
以下是.ned文件
simple computer
{
parameters:
gates:
input in1;
output out1;
input in2;
output out2;
}
//
// TODO documentation
//
network Network
{
@display("bgb=538,302");
submodules:
A: computer {
@display("p=30,88");
}
B: computer {
@display("p=344,96");
}
C: computer {
@display("p=209,199");
}
connections:
A.out1 --> B.in1;
B.out1 --> A.in1;
A.out2 --> C.in1;
C.out1 --> A.in2;
C.out2 --> B.in2;
B.out2 --> C.in2;
}
以下是.cc源文件
#include <string.h>
#include <omnetpp.h>
#include <string>
class computer: public cSimpleModule
{
public:
virtual void initialize();
virtual void handleMessage(cMessage *msg);
};
//----------------------------------------------------------------------
Define_Module(computer);
void computer::initialize()
{
if (strcmp("A", getName()) == 0)
{
send(msg, "out1");
cMessage *copy = (cMessage *) msg->dup();
send(copy, "out2");
}
}
void computer::handleMessage(cMessage *msg)
{
}
现在我的问题是,在初始化函数中,节点A向B和C发送消息.此后,我想从节点B发送消息,从节点B向节点A和C发送消息.类似地,在此之后,我想从节点C到A和B(例如距离矢量协议)我该怎么做?
Now my question is that in the initialize function node A sends message to B and C. After that i want to send message from node B , FROM NODE B to node A and C. Similarly after that i want to send message from node C to A and B (like distance vector protocol) How can i do that?
此外,第二个问题是我如何同时从所有节点向邻居节点发送消息,即A向B,C发送消息; B向A,c发送消息; C发送到A,B.全部,A B C同时发送消息吗? 让我让它更简洁明了. A向B发送消息如下
Moreover the second question is that how can i send message from all the nodes at the same time to the neighbor nodes i-e A sending message to B,C ; B sending message to A,c ; C sending to A,B. All, A B C sending messages at the same time? Let me make it more brief and clear. A sends message to B as follows
以下是.cc源文件
#include <string.h>
#include <omnetpp.h>
#include <string>
class computer: public cSimpleModule
{
public:
virtual void initialize();
virtual void handleMessage(cMessage *msg);
};
//----------------------------------------------------------------------
Define_Module(computer);
void computer::initialize()
{
if (strcmp("A", getName()) == 0)
{
send(msg, "out1");
}
}
handleMessage(cMessage * msg) { 现在如何从C到A发送消息 }
handleMessage(cMessage *msg) { Now how to send message from C TO A }
A至B 从C到A?
推荐答案
在这样做之前,您必须回答此问题,C如何才能知道B收到了这样的味精?您有2个解决方案:
Before doing so, you must answer to this questio, how C can know that B received such msg ? You have 2 solutions:
-
从网络角度来看的
- 逻辑解决方案:在这样做之前 您必须向C发送一条消息,以阻止他们接收 这样的味精
- 较少逻辑的解决方案:通过检查B处的bool值 C模块中的模块,并决定此时发送一条消息, 或通过在B处创建一个信号并使用它来更好地使用信号 C模块(请查看omnet ++ doc).
- Logic solution from a networking point of view: Before doing so you have to sent a message to C preventing them of the reception of such msg
- Less logical solution: By checking a bool value at B module from C module, and decide at this moment to send a message, or better use signals by creating one at B and suscribing to it the C module (check omnet++ doc).
祝你好运
这篇关于同时从所有节点发送消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!