How to send message continuously?

28 views
Skip to first unread message

shahzad...@gmail.com

unread,
Jul 17, 2017, 2:40:15 PM7/17/17
to OMNeT++ Users
hi every one, i am new to omnet++. it is really a great platform for simulation of communication protocols. i have a problem. i want to send a message continuously for example say after every 1 sec. i tried but could not succeed. the code is as below

void Wireless :: initialize()
{
    if(par("sendInitMsg").boolValue()==true)
    {
        EV<<"Sending initial message....\n";    // printing statement
        target = getParentModule()->getSubmodule("wireless1"); // defining a module
        cMessage *msg = new cMessage("tictocMsg"); // creating a message
        simtime_t delay_t = 0.5;
        simtime_t dur = 1.0;
        sendDirect(msg,simtime_t delay_t,target,"radioIn"); // sendDirect message
    }
}

void Wireless :: handleMessage(cMessage *msg)
{

    delete msg;
}

Kindly can anybody help me in sending a message say after 1 sec.
Thanks

Alfonso Ariza Quintana

unread,
Jul 17, 2017, 4:54:43 PM7/17/17
to omn...@googlegroups.com

With scheduleAt, see the examples

 

void Wireless :: initialize()

{

    if(par("sendInitMsg").boolValue()==true)

    {

        EV<<"Sending initial message....\n";    // printing statement

        target = getParentModule()->getSubmodule("wireless1"); // defining a module

        cMessage *msg = new cMessage("tictocMsg"); // creating a message

        simtime_t delay_t = 0.5;

        simtime_t dur = 1.0;

        sendDirect(msg,0,target,"radioIn"); // sendDirect

message

       cMessage *msg2 = new cMessage();

       scheduleAt(msg2,siTime()+1);

    }

}

 

void Wireless :: handleMessage(cMessage *msg)

{

  If (msg->isSelfMessage()) {

        target = getParentModule()->getSubmodule("wireless1"); // defining a module

        cMessage *msg2 = new cMessage("tictocMsg"); // creating a message

        sendDirect(msg,0,target,"radioIn"); // sendDirect message

       cMessage *msg2 = new cMessage();

       scheduleAt(msg,siTime()+1);

 

  }

 

 

Enviado desde Correo para Windows 10

--
You received this message because you are subscribed to the Google Groups "OMNeT++ Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to omnetpp+u...@googlegroups.com.
Visit this group at https://groups.google.com/group/omnetpp.
For more options, visit https://groups.google.com/d/optout.

 

shahzad...@gmail.com

unread,
Jul 17, 2017, 10:07:17 PM7/17/17
to OMNeT++ Users, aari...@hotmail.com
Sir thank you very much. it has worked for me. 
Reply all
Reply to author
Forward
0 new messages