从节点向其邻居发送消息

时间:2016-03-15 14:10:12

标签: c++ omnet++

我有一个节点网络,我希望从ID 401识别的节点向其邻居发送消息。以下是我使用的代码:

for(int i = 0; i < 8; i++)
{
    cMessage *copy = msg->dup();
    send(copy, "out", i);
}
delete msg;

以下是我收到的错误消息

<!> Error in module (Node) topo. nd[401] (id=404) during network initialization: send()/sendDelayed(): Gate index 0 out of range when accessing vector gate `out[]' with size 0.

1 个答案:

答案 0 :(得分:3)

此错误表示:

  • gate outNED文件中声明为向量(可能就是这样:output out[];
  • gate out尚未连接到任何其他节点(即大小等于0)

您应该做的是将节点的门out连接到每个其他节点的输入门。 此外,我建议在for循环中检查out向量的大小,例如:

    for (int i = 0; i < gate("out", 0)->getVectorSize(); ++i) {
       // ...
    }

注意:只有至少连接了out的一个端口时,上述代码才能正常工作。