#include <TCPEchoApp.h>
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 |
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] |
long TCPEchoApp::bytesRcvd [protected] |
long TCPEchoApp::bytesSent [protected] |
double TCPEchoApp::delay [protected] |
double TCPEchoApp::echoFactor [protected] |