Hi all,
I have created a network like this:
The code is :
/*
* Sample2.cc
*
* Created on: Jun 27, 2016
* Author: subhrajit
*/
#include <string.h>
#include <omnetpp.h>
using namespace omnetpp;
class Sample2 : public cSimpleModule
{
bool homeNode = false;
int cont = 0;
protected:
virtual void initialize() override;
virtual void handleMessage(cMessage *msg) override;
};
Define_Module(Sample2);
void Sample2::initialize()
{
if (strcmp("sample2", getName()) == 0) {
// The `ev' object works like `cout' in C++.
EV << "Sending initial message\n";
homeNode = true;
cMessage *msg = new cMessage("Subhrajit");
send(msg, "gate$o",1);
}
}
void Sample2::handleMessage(cMessage *msg)
{
if (homeNode)
{
// do something
cont++;
msg->setName("abcd");
}
int n = gateSize("gate");
int k = intuniform(0, n-1);
EV << "Forwarding message " << msg << " on gate[" << k << "]\n";
send(msg, "gate$o", k);
// msg->getName() is name of the msg object, here it will be "tictocMsg".
EV << "Received message `" << msg->getName() << "', sending it out again\n";
}
NOW THE MESSGAE IS GETTING CHANGED ONLY THE FIRST TIME IT IS REACHING THE CENTRAL NODE(SAMPLE2)BUT I WANT TO UPDATE THE MESSAGE EACH AND EVERY TIME IT VISITS THE CENTRAL NODE(SAMPLE2). SUPPOSE THE FIRST TIME THE MESSAGE WILL BE "ABC".NEXT TIME THE NEXT LETTER WILL ADD AND IT WILL BE" ABCD" AND SO ON. CAN ANYONE PLEASE TELL ME WHAT TO DO IN THE CODE TO DO LIKE THIS.
THANK YOU.