简体   繁体   中英

Sending a message from a node to its neighbour

I am trying to create a grid network and send messages. My Node is as follows:

simple Node
{
    parameters:
        @display("i=misc/node");
        gates:
        inout up;
        inout left;
        inout down;
        inout right;
}

And i am sending a msg as follows:

if(this->gate("right$o")->isConnected())
        {
            send(msg,"right$o",k);
        }

It doesn't give any build errors but gives an error in simulation. What am i doing wrong? The error is as below:

send()/sendDelayed(): Scalar gate 'right$o' referenced with index -- in module (Node) GridNetwork.sensor[0] (id=2), at t=0s, event #1

Your example Node has a inout right gate, which is a scalar inout gate rather than a vector. This means that there's only one, and it has two gates: right$i and right$o , as you're trying to use in your example.

You must thus replace inout right with inout right[] , as well as create connections from it to another gate. See the OMNeT++ documentation on gates .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM