#include <TCPEchoApp.h>
Protected Member Functions | |
virtual void | sendDown (cMessage *msg) |
virtual void | initialize () |
virtual void | handleMessage (cMessage *msg) |
virtual void | finish () |
Protected Attributes | |
simtime_t | delay |
double | echoFactor |
long | bytesRcvd |
long | bytesSent |
Accepts any number of incoming connections, and sends back whatever arrives on them.
Definition at line 26 of file TCPEchoApp.h.
void TCPEchoApp::finish | ( | ) | [protected, virtual] |
Definition at line 104 of file TCPEchoApp.cc.
void TCPEchoApp::handleMessage | ( | cMessage * | msg | ) | [protected, virtual] |
Definition at line 46 of file TCPEchoApp.cc.
{ if (msg->isSelfMessage()) { sendDown(msg); } else if (msg->getKind()==TCP_I_PEER_CLOSED) { // we'll close too msg->setKind(TCP_C_CLOSE); if (delay==0) sendDown(msg); else scheduleAt(simTime()+delay, msg); // send after a delay } else if (msg->getKind()==TCP_I_DATA || msg->getKind()==TCP_I_URGENT_DATA) { cPacket *pkt = check_and_cast<cPacket *>(msg); bytesRcvd += pkt->getByteLength(); if (echoFactor==0) { delete pkt; } else { // reverse direction, modify length, and send it back pkt->setKind(TCP_C_SEND); TCPCommand *ind = check_and_cast<TCPCommand *>(pkt->removeControlInfo()); TCPSendCommand *cmd = new TCPSendCommand(); cmd->setConnId(ind->getConnId()); pkt->setControlInfo(cmd); delete ind; long byteLen = pkt->getByteLength()*echoFactor; if (byteLen<1) byteLen=1; pkt->setByteLength(byteLen); if (delay==0) sendDown(pkt); else scheduleAt(simTime()+delay, pkt); // send after a delay } } else { // some indication -- ignore delete msg; } if (ev.isGUI()) { char buf[80]; sprintf(buf, "rcvd: %ld bytes\nsent: %ld bytes", bytesRcvd, bytesSent); getDisplayString().setTagArg("t",0,buf); } }
void TCPEchoApp::initialize | ( | ) | [protected, virtual] |
Definition at line 22 of file TCPEchoApp.cc.
{ const char *address = par("address"); int port = par("port"); delay = par("echoDelay"); echoFactor = par("echoFactor"); bytesRcvd = bytesSent = 0; WATCH(bytesRcvd); WATCH(bytesSent); TCPSocket socket; socket.setOutputGate(gate("tcpOut")); socket.bind(address[0] ? IPvXAddress(address) : IPvXAddress(), port); socket.listen(); }
void TCPEchoApp::sendDown | ( | cMessage * | msg | ) | [protected, virtual] |
Definition at line 39 of file TCPEchoApp.cc.
Referenced by handleMessage().
{ if (msg->isPacket()) bytesSent += ((cPacket *)msg)->getByteLength(); send(msg, "tcpOut"); }
long TCPEchoApp::bytesRcvd [protected] |
Definition at line 32 of file TCPEchoApp.h.
Referenced by finish(), handleMessage(), and initialize().
long TCPEchoApp::bytesSent [protected] |
Definition at line 33 of file TCPEchoApp.h.
Referenced by finish(), handleMessage(), initialize(), and sendDown().
simtime_t TCPEchoApp::delay [protected] |
Definition at line 29 of file TCPEchoApp.h.
Referenced by handleMessage(), and initialize().
double TCPEchoApp::echoFactor [protected] |
Definition at line 30 of file TCPEchoApp.h.
Referenced by handleMessage(), and initialize().