void SimpleHost::initialize()
{
msgId = 0;
printf("********** NAME %s ***********\n", getName());
printf("HAS GATES %d\n", hasGates());
vector<string> mygates = getGateNames();
for (auto i = mygates.begin(); i != mygates.end(); ++i)
printf("GATES %s\n", (*i).c_str());
if (strcmp("shostA", getName()) == 0)
{
printf("I’m host 0, sending initial message\n");
inet::cMessage *msg = new inet::cMessage("InitialMsg");
send(msg, "out");
}
}
void SimpleHost::handleMessage(inet::cMessage *msg)
{
char msgStr [32];
printf("Received message ‘%s'\n", msg->getName());
printf("********** NAME 1 %s ***********\n", getName());
if (strcmp("shostA", getName()) == 0)
{
printf("I’m host 0, sending the message\n");
sprintf(msgStr, "HOSTA-MSG-%d", msgId++);
}
else if (strcmp("shostB", getName()) == 0)
{
printf("I’m host 1, sending the message\n");
sprintf(msgStr, "HOSTB-MSG-%d", msgId++);
}
inet::cMessage *newMsg = new inet::cMessage(msgStr);
send(newMsg, "out");
delete msg;
}