Mustapha Dia Eddine
Mustapha Dia Eddine

Reputation: 21

Sending a message from a node to its neighboors

I got a network of nodes where i want to send a message from the node identified by the ID 401 to its neighbors. Below is the code i used:

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

Below is the error message that I got

<!> 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.

Upvotes: 2

Views: 1143

Answers (1)

Jerzy D.
Jerzy D.

Reputation: 7002

This error means that:

  • gate out was declared in NED file as a vector (probably this way: output out[];)
  • gate out has not been connected to any other nodes (i.e. it has size equal to 0)

What you should do is to connect gate out of your node to an input gate of every other node. Moreover, I suggest checking size of out vector in for loop, for example:

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

Note: the above code will properly work only if at least one port of out is connected.

Upvotes: 3

Related Questions