#include <TelnetApp.h>
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, cPacket *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 |
An example Telnet client application. The server app should be TCPGenericSrvApp.
Definition at line 23 of file TelnetApp.h.
| TelnetApp::TelnetApp | ( | ) |
Definition at line 25 of file TelnetApp.cc.
{
timeoutMsg = NULL;
}
| TelnetApp::~TelnetApp | ( | ) | [virtual] |
Definition at line 30 of file TelnetApp.cc.
{
cancelAndDelete(timeoutMsg);
}
| void TelnetApp::handleTimer | ( | cMessage * | msg | ) | [protected, virtual] |
Redefined.
Implements TCPGenericCliAppBase.
Definition at line 49 of file TelnetApp.cc.
{
switch (msg->getKind())
{
case MSGKIND_CONNECT:
EV << "user fires up telnet program\n";
connect();
break;
case MSGKIND_SEND:
if (numCharsToType>0)
{
// user types a character and expects it to be echoed
EV << "user types one character, " << numCharsToType-1 << " more to go\n";
sendPacket(1,1);
scheduleAt(simTime()+(simtime_t)par("keyPressDelay"), timeoutMsg);
numCharsToType--;
}
else
{
EV << "user hits Enter key\n";
// Note: reply length must be at least 2, otherwise we'll think
// it's an echo when it comes back!
sendPacket(1, 2+(long)par("commandOutputLength"));
numCharsToType = (long)par("commandLength");
// Note: no scheduleAt(), because user only starts typing next command
// when output from previous one has arrived (see socketDataArrived())
}
break;
case MSGKIND_CLOSE:
EV << "user exits telnet program\n";
close();
break;
}
}
| void TelnetApp::initialize | ( | ) | [protected, virtual] |
Redefined to schedule a connect().
Reimplemented from TCPGenericCliAppBase.
Definition at line 35 of file TelnetApp.cc.
{
TCPGenericCliAppBase::initialize();
timeoutMsg = new cMessage("timer");
numCharsToType = numLinesToType = 0;
WATCH(numCharsToType);
WATCH(numLinesToType);
timeoutMsg->setKind(MSGKIND_CONNECT);
scheduleAt((simtime_t)par("startTime"), timeoutMsg);
}
| void TelnetApp::socketClosed | ( | int | connId, | |
| void * | yourPtr | |||
| ) | [protected, virtual] |
Redefined to start another session after a delay.
Reimplemented from TCPGenericCliAppBase.
Definition at line 132 of file TelnetApp.cc.
{
TCPGenericCliAppBase::socketClosed(connId, ptr);
// start another session after a delay
timeoutMsg->setKind(MSGKIND_CONNECT);
scheduleAt(simTime()+(simtime_t)par("idleInterval"), timeoutMsg);
}
| void TelnetApp::socketDataArrived | ( | int | connId, | |
| void * | yourPtr, | |||
| cPacket * | msg, | |||
| bool | urgent | |||
| ) | [protected, virtual] |
Redefined.
Reimplemented from TCPGenericCliAppBase.
Definition at line 98 of file TelnetApp.cc.
{
int len = msg->getByteLength();
TCPGenericCliAppBase::socketDataArrived(connId, ptr, msg, urgent);
if (len==1)
{
// this is an echo, ignore
EV << "received echo\n";
}
else
{
// output from last typed command arrived.
EV << "received output of command typed\n";
// If user has finished working, she closes the connection, otherwise
// starts typing again after a delay
numLinesToType--;
if (numLinesToType==0)
{
EV << "user has no more commands to type\n";
timeoutMsg->setKind(MSGKIND_CLOSE);
scheduleAt(simTime()+(simtime_t)par("thinkTime"), timeoutMsg);
}
else
{
EV << "user looks at output, then starts typing next command\n";
timeoutMsg->setKind(MSGKIND_SEND);
scheduleAt(simTime()+(simtime_t)par("thinkTime"), timeoutMsg);
}
}
}
| void TelnetApp::socketEstablished | ( | int | connId, | |
| void * | yourPtr | |||
| ) | [protected, virtual] |
Redefined.
Reimplemented from TCPGenericCliAppBase.
Definition at line 87 of file TelnetApp.cc.
{
TCPGenericCliAppBase::socketEstablished(connId, ptr);
// schedule first sending
numLinesToType = (long) par("numCommands");
numCharsToType = (long) par("commandLength");
timeoutMsg->setKind(numLinesToType>0 ? MSGKIND_SEND : MSGKIND_CLOSE);
scheduleAt(simTime()+(simtime_t)par("thinkTime"), timeoutMsg);
}
| void TelnetApp::socketFailure | ( | int | connId, | |
| void * | yourPtr, | |||
| int | code | |||
| ) | [protected, virtual] |
Redefined to reconnect after a delay.
Reimplemented from TCPGenericCliAppBase.
Definition at line 141 of file TelnetApp.cc.
{
TCPGenericCliAppBase::socketFailure(connId, ptr, code);
// reconnect after a delay
timeoutMsg->setKind(MSGKIND_CONNECT);
scheduleAt(simTime()+(simtime_t)par("reconnectInterval"), timeoutMsg);
}
int TelnetApp::numCharsToType [protected] |
Definition at line 28 of file TelnetApp.h.
Referenced by handleTimer(), initialize(), and socketEstablished().
int TelnetApp::numLinesToType [protected] |
Definition at line 27 of file TelnetApp.h.
Referenced by initialize(), socketDataArrived(), and socketEstablished().
cMessage* TelnetApp::timeoutMsg [protected] |
Definition at line 26 of file TelnetApp.h.
Referenced by handleTimer(), initialize(), socketClosed(), socketDataArrived(), socketEstablished(), socketFailure(), TelnetApp(), and ~TelnetApp().
1.7.1