30 #include "IPAddressResolver.h"
46 cancelAndDelete(timerMsg);
56 sendPeriod = par(
"sendPeriod");
67 timerMsg =
new cMessage(
"Periodic timer");
70 bindAndListenTcp(24000);
77 if (globalNodeList->getNumNodes() == 1) {
78 scheduleAt(simTime() + SimTime::parse(
"20s"), timerMsg);
85 globalStatistics->addStdDev(
"TCPExampleApp: Sent packets", numSent);
86 globalStatistics->addStdDev(
"TCPExampleApp: Received packets", numReceived);
92 if (msg == timerMsg) {
95 if (underlayConfigurator->isInInitPhase()) {
96 scheduleAt(simTime() + sendPeriod, timerMsg);
101 if (globalNodeList->getNumNodes() == 1){
102 scheduleAt(simTime() + sendPeriod, timerMsg);
108 while ((addr != NULL) && (thisNode.getIp().equals(addr->
getIp()))) {
109 addr = globalNodeList->getRandomAliveNode();
112 assert(addr != NULL);
118 TCPMsg->setByteLength(100);
124 establishTcpConnection(remoteAddress);
125 sendTcpData(TCPMsg, remoteAddress);
128 EV << thisNode.getIp() <<
": Connecting to "<< addr->
getIp()
129 <<
" and sending PING."<< std::endl;
145 respMsg->setByteLength(100);
147 sendTcpData(respMsg, address);
152 EV << thisNode.getIp() <<
": Got PING from "
158 EV << thisNode.getIp() <<
": Got PONG reply! Closing connection." << std::endl;
161 closeTcpConnection(address);
169 if (code == PEER_CLOSED) {
170 scheduleAt(simTime() + sendPeriod, timerMsg);