TCPEchoApp Class Reference

#include <TCPEchoApp.h>

List of all members.


Detailed Description

Accepts any number of incoming connections, and sends back whatever arrives on them.


Protected Member Functions

void sendOrSchedule (cMessage *msg)
virtual void initialize ()
virtual void handleMessage (cMessage *msg)
virtual void finish ()

Protected Attributes

double delay
double echoFactor
long bytesRcvd
long bytesSent


Member Function Documentation

void TCPEchoApp::finish (  )  [protected, virtual]

00104 {
00105 }

void TCPEchoApp::handleMessage ( cMessage *  msg  )  [protected, virtual]

00053 {
00054     if (msg->isSelfMessage())
00055     {
00056         bytesSent += msg->byteLength();
00057         send(msg, "tcpOut");
00058     }
00059     else if (msg->kind()==TCP_I_PEER_CLOSED)
00060     {
00061         // we'll close too
00062         msg->setKind(TCP_C_CLOSE);
00063         sendOrSchedule(msg);
00064     }
00065     else if (msg->kind()==TCP_I_DATA || msg->kind()==TCP_I_URGENT_DATA)
00066     {
00067         bytesRcvd += msg->byteLength();
00068         if (echoFactor==0)
00069         {
00070             delete msg;
00071         }
00072         else
00073         {
00074             // reverse direction, modify length, and send it back
00075             msg->setKind(TCP_C_SEND);
00076             TCPCommand *ind = check_and_cast<TCPCommand *>(msg->removeControlInfo());
00077             TCPSendCommand *cmd = new TCPSendCommand();
00078             cmd->setConnId(ind->connId());
00079             msg->setControlInfo(cmd);
00080             delete ind;
00081 
00082             long byteLen = msg->byteLength()*echoFactor;
00083             if (byteLen<1) byteLen=1;
00084             msg->setByteLength(byteLen);
00085 
00086             sendOrSchedule(msg);
00087         }
00088     }
00089     else
00090     {
00091         // some indication -- ignore
00092         delete msg;
00093     }
00094 
00095     if (ev.isGUI())
00096     {
00097         char buf[80];
00098         sprintf(buf, "rcvd: %ld bytes\nsent: %ld bytes", bytesRcvd, bytesSent);
00099         displayString().setTagArg("t",0,buf);
00100     }
00101 }

void TCPEchoApp::initialize (  )  [protected, virtual]

00023 {
00024     const char *address = par("address");
00025     int port = par("port");
00026     delay = par("echoDelay");
00027     echoFactor = par("echoFactor");
00028 
00029     bytesRcvd = bytesSent = 0;
00030     WATCH(bytesRcvd);
00031     WATCH(bytesSent);
00032 
00033     TCPSocket socket;
00034     socket.setOutputGate(gate("tcpOut"));
00035     socket.bind(address[0] ? IPvXAddress(address) : IPvXAddress(), port);
00036     socket.listen();
00037 }

void TCPEchoApp::sendOrSchedule ( cMessage *  msg  )  [protected]

00040 {
00041     if (delay==0)
00042     {
00043         bytesSent += msg->byteLength();
00044         send(msg, "tcpOut");
00045     }
00046     else
00047     {
00048         scheduleAt(simTime()+delay, msg);
00049     }
00050 }


Member Data Documentation

long TCPEchoApp::bytesRcvd [protected]

long TCPEchoApp::bytesSent [protected]

double TCPEchoApp::delay [protected]

double TCPEchoApp::echoFactor [protected]


The documentation for this class was generated from the following files:
Generated on Wed Apr 4 13:20:24 2007 for INET Framework for OMNeT++/OMNEST by  doxygen 1.4.7