#include <TelnetApp.h>
Inheritance diagram for TelnetApp:
Public Member Functions | |
TelnetApp () | |
virtual | ~TelnetApp () |
Protected Member Functions | |
virtual void | initialize () |
virtual void | handleTimer (cMessage *msg) |
virtual void | socketEstablished (int connId, void *yourPtr) |
virtual void | socketDataArrived (int connId, void *yourPtr, cMessage *msg, bool urgent) |
virtual void | socketClosed (int connId, void *yourPtr) |
virtual void | socketFailure (int connId, void *yourPtr, int code) |
Protected Attributes | |
cMessage * | timeoutMsg |
int | numLinesToType |
int | numCharsToType |
TelnetApp::TelnetApp | ( | ) |
TelnetApp::~TelnetApp | ( | ) | [virtual] |
void TelnetApp::handleTimer | ( | cMessage * | msg | ) | [protected, virtual] |
Redefined.
Implements TCPGenericCliAppBase.
00050 { 00051 switch (msg->kind()) 00052 { 00053 case MSGKIND_CONNECT: 00054 EV << "user fires up telnet program\n"; 00055 connect(); 00056 break; 00057 00058 case MSGKIND_SEND: 00059 if (numCharsToType>0) 00060 { 00061 // user types a character and expects it to be echoed 00062 EV << "user types one character, " << numCharsToType-1 << " more to go\n"; 00063 sendPacket(1,1); 00064 scheduleAt(simTime()+(simtime_t)par("keyPressDelay"), timeoutMsg); 00065 numCharsToType--; 00066 } 00067 else 00068 { 00069 EV << "user hits Enter key\n"; 00070 // Note: reply length must be at least 2, otherwise we'll think 00071 // it's an echo when it comes back! 00072 sendPacket(1, 2+(long)par("commandOutputLength")); 00073 numCharsToType = (long)par("commandLength"); 00074 00075 // Note: no scheduleAt(), because user only starts typing next command 00076 // when output from previous one has arrived (see socketDataArrived()) 00077 } 00078 break; 00079 00080 case MSGKIND_CLOSE: 00081 EV << "user exits telnet program\n"; 00082 close(); 00083 break; 00084 } 00085 }
void TelnetApp::initialize | ( | ) | [protected, virtual] |
Redefined to schedule a connect().
Reimplemented from TCPGenericCliAppBase.
00036 { 00037 TCPGenericCliAppBase::initialize(); 00038 00039 timeoutMsg = new cMessage("timer"); 00040 00041 numCharsToType = numLinesToType = 0; 00042 WATCH(numCharsToType); 00043 WATCH(numLinesToType); 00044 00045 timeoutMsg->setKind(MSGKIND_CONNECT); 00046 scheduleAt((simtime_t)par("startTime"), timeoutMsg); 00047 }
void TelnetApp::socketClosed | ( | int | connId, | |
void * | yourPtr | |||
) | [protected, virtual] |
Redefined to start another session after a delay.
Reimplemented from TCPGenericCliAppBase.
00133 { 00134 TCPGenericCliAppBase::socketClosed(connId, ptr); 00135 00136 // start another session after a delay 00137 timeoutMsg->setKind(MSGKIND_CONNECT); 00138 scheduleAt(simTime()+(simtime_t)par("idleInterval"), timeoutMsg); 00139 }
void TelnetApp::socketDataArrived | ( | int | connId, | |
void * | yourPtr, | |||
cMessage * | msg, | |||
bool | urgent | |||
) | [protected, virtual] |
Redefined.
Reimplemented from TCPGenericCliAppBase.
00099 { 00100 int len = msg->byteLength(); 00101 TCPGenericCliAppBase::socketDataArrived(connId, ptr, msg, urgent); 00102 00103 if (len==1) 00104 { 00105 // this is an echo, ignore 00106 EV << "received echo\n"; 00107 } 00108 else 00109 { 00110 // output from last typed command arrived. 00111 EV << "received output of command typed\n"; 00112 00113 // If user has finished working, she closes the connection, otherwise 00114 // starts typing again after a delay 00115 numLinesToType--; 00116 00117 if (numLinesToType==0) 00118 { 00119 EV << "user has no more commands to type\n"; 00120 timeoutMsg->setKind(MSGKIND_CLOSE); 00121 scheduleAt(simTime()+(simtime_t)par("thinkTime"), timeoutMsg); 00122 } 00123 else 00124 { 00125 EV << "user looks at output, then starts typing next command\n"; 00126 timeoutMsg->setKind(MSGKIND_SEND); 00127 scheduleAt(simTime()+(simtime_t)par("thinkTime"), timeoutMsg); 00128 } 00129 } 00130 }
void TelnetApp::socketEstablished | ( | int | connId, | |
void * | yourPtr | |||
) | [protected, virtual] |
Redefined.
Reimplemented from TCPGenericCliAppBase.
00088 { 00089 TCPGenericCliAppBase::socketEstablished(connId, ptr); 00090 00091 // schedule first sending 00092 numLinesToType = (long) par("numCommands"); 00093 numCharsToType = (long) par("commandLength"); 00094 timeoutMsg->setKind(numLinesToType>0 ? MSGKIND_SEND : MSGKIND_CLOSE); 00095 scheduleAt(simTime()+(simtime_t)par("thinkTime"), timeoutMsg); 00096 }
void TelnetApp::socketFailure | ( | int | connId, | |
void * | yourPtr, | |||
int | code | |||
) | [protected, virtual] |
Redefined to reconnect after a delay.
Reimplemented from TCPGenericCliAppBase.
00142 { 00143 TCPGenericCliAppBase::socketFailure(connId, ptr, code); 00144 00145 // reconnect after a delay 00146 timeoutMsg->setKind(MSGKIND_CONNECT); 00147 scheduleAt(simTime()+(simtime_t)par("reconnectInterval"), timeoutMsg); 00148 }
int TelnetApp::numCharsToType [protected] |
int TelnetApp::numLinesToType [protected] |
cMessage* TelnetApp::timeoutMsg [protected] |