TCPBasicClientApp Class Reference

#include <TCPBasicClientApp.h>

Inheritance diagram for TCPBasicClientApp:

TCPGenericCliAppBase TCPSocket::CallbackInterface

List of all members.


Detailed Description

An example request-reply based client application.

Public Member Functions

 TCPBasicClientApp ()
virtual ~TCPBasicClientApp ()

Protected Member Functions

virtual void sendRequest ()
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
bool earlySend
int numRequestsToSend

Constructor & Destructor Documentation

TCPBasicClientApp::TCPBasicClientApp (  ) 

00029 {
00030     timeoutMsg = NULL;
00031 }

TCPBasicClientApp::~TCPBasicClientApp (  )  [virtual]

00034 {
00035     cancelAndDelete(timeoutMsg);
00036 }


Member Function Documentation

void TCPBasicClientApp::sendRequest (  )  [protected, virtual]

Utility: sends a request to the server

Referenced by handleTimer(), and socketEstablished().

00054 {
00055      EV << "sending request, " << numRequestsToSend-1 << " more to go\n";
00056 
00057      long requestLength = par("requestLength");
00058      long replyLength = par("replyLength");
00059      if (requestLength<1) requestLength=1;
00060      if (replyLength<1) replyLength=1;
00061 
00062      sendPacket(requestLength, replyLength);
00063 }

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

Redefined to schedule a connect().

Reimplemented from TCPGenericCliAppBase.

00039 {
00040     TCPGenericCliAppBase::initialize();
00041 
00042     timeoutMsg = new cMessage("timer");
00043 
00044     numRequestsToSend = 0;
00045     earlySend = false;  // TBD make it parameter
00046     WATCH(numRequestsToSend);
00047     WATCH(earlySend);
00048 
00049     timeoutMsg->setKind(MSGKIND_CONNECT);
00050     scheduleAt((simtime_t)par("startTime"), timeoutMsg);
00051 }

void TCPBasicClientApp::handleTimer ( cMessage *  msg  )  [protected, virtual]

Redefined.

Implements TCPGenericCliAppBase.

00066 {
00067     switch (msg->getKind())
00068     {
00069         case MSGKIND_CONNECT:
00070             EV << "starting session\n";
00071             connect(); // active OPEN
00072 
00073             // significance of earlySend: if true, data will be sent already
00074             // in the ACK of SYN, otherwise only in a separate packet (but still
00075             // immediately)
00076             if (earlySend)
00077                 sendRequest();
00078             break;
00079 
00080         case MSGKIND_SEND:
00081            sendRequest();
00082            numRequestsToSend--;
00083            // no scheduleAt(): next request will be sent when reply to this one
00084            // arrives (see socketDataArrived())
00085            break;
00086     }
00087 }

void TCPBasicClientApp::socketEstablished ( int  connId,
void *  yourPtr 
) [protected, virtual]

Redefined.

Reimplemented from TCPGenericCliAppBase.

00090 {
00091     TCPGenericCliAppBase::socketEstablished(connId, ptr);
00092 
00093     // determine number of requests in this session
00094     numRequestsToSend = (long) par("numRequestsPerSession");
00095     if (numRequestsToSend<1) numRequestsToSend=1;
00096 
00097     // perform first request if not already done (next one will be sent when reply arrives)
00098     if (!earlySend)
00099         sendRequest();
00100     numRequestsToSend--;
00101 }

void TCPBasicClientApp::socketDataArrived ( int  connId,
void *  yourPtr,
cPacket *  msg,
bool  urgent 
) [protected, virtual]

Redefined.

Reimplemented from TCPGenericCliAppBase.

00104 {
00105     TCPGenericCliAppBase::socketDataArrived(connId, ptr, msg, urgent);
00106 
00107     if (numRequestsToSend>0)
00108     {
00109         EV << "reply arrived\n";
00110         timeoutMsg->setKind(MSGKIND_SEND);
00111         scheduleAt(simTime()+(simtime_t)par("thinkTime"), timeoutMsg);
00112     }
00113     else
00114     {
00115         EV << "reply to last request arrived, closing session\n";
00116         close();
00117     }
00118 }

void TCPBasicClientApp::socketClosed ( int  connId,
void *  yourPtr 
) [protected, virtual]

Redefined to start another session after a delay.

Reimplemented from TCPGenericCliAppBase.

00121 {
00122     TCPGenericCliAppBase::socketClosed(connId, ptr);
00123 
00124     // start another session after a delay
00125     timeoutMsg->setKind(MSGKIND_CONNECT);
00126     scheduleAt(simTime()+(simtime_t)par("idleInterval"), timeoutMsg);
00127 }

void TCPBasicClientApp::socketFailure ( int  connId,
void *  yourPtr,
int  code 
) [protected, virtual]

Redefined to reconnect after a delay.

Reimplemented from TCPGenericCliAppBase.

00130 {
00131     TCPGenericCliAppBase::socketFailure(connId, ptr, code);
00132 
00133     // reconnect after a delay
00134     timeoutMsg->setKind(MSGKIND_CONNECT);
00135     scheduleAt(simTime()+(simtime_t)par("reconnectInterval"), timeoutMsg);
00136 }


Member Data Documentation

cMessage* TCPBasicClientApp::timeoutMsg [protected]

bool TCPBasicClientApp::earlySend [protected]


The documentation for this class was generated from the following files:

Generated on Fri Mar 20 18:51:22 2009 for INET Framework for OMNeT++/OMNEST by  doxygen 1.5.5