Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

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

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


Constructor & Destructor Documentation

TCPBasicClientApp::TCPBasicClientApp  ) 
 

00025 {
00026     timeoutMsg = NULL;
00027 }

TCPBasicClientApp::~TCPBasicClientApp  )  [virtual]
 

00030 {
00031     cancelAndDelete(timeoutMsg);
00032 }


Member Function Documentation

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

Redefined.

Implements TCPGenericCliAppBase.

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

void TCPBasicClientApp::initialize  )  [protected, virtual]
 

Redefined to schedule a connect().

Reimplemented from TCPGenericCliAppBase.

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

void TCPBasicClientApp::sendRequest  )  [protected]
 

Utility: sends a request to the server

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

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

Redefined to start another session after a delay.

Reimplemented from TCPGenericCliAppBase.

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

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

Redefined.

Reimplemented from TCPGenericCliAppBase.

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

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

Redefined.

Reimplemented from TCPGenericCliAppBase.

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

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

Redefined to reconnect after a delay.

Reimplemented from TCPGenericCliAppBase.

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


Member Data Documentation

bool TCPBasicClientApp::earlySend [protected]
 

int TCPBasicClientApp::numRequestsToSend [protected]
 

cMessage* TCPBasicClientApp::timeoutMsg [protected]
 


The documentation for this class was generated from the following files:
Generated on Sat Apr 1 20:52:24 2006 for INET Framework for OMNeT++/OMNEST by  doxygen 1.4.1