#include <TCPBasicClientApp.h>
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 |
An example request-reply based client application.
Definition at line 24 of file TCPBasicClientApp.h.
TCPBasicClientApp::TCPBasicClientApp | ( | ) |
Definition at line 28 of file TCPBasicClientApp.cc.
{ timeoutMsg = NULL; }
TCPBasicClientApp::~TCPBasicClientApp | ( | ) | [virtual] |
Definition at line 33 of file TCPBasicClientApp.cc.
{ cancelAndDelete(timeoutMsg); }
void TCPBasicClientApp::handleTimer | ( | cMessage * | msg | ) | [protected, virtual] |
Redefined.
Implements TCPGenericCliAppBase.
Definition at line 65 of file TCPBasicClientApp.cc.
{ switch (msg->getKind()) { case MSGKIND_CONNECT: EV << "starting session\n"; connect(); // active OPEN // significance of earlySend: if true, data will be sent already // in the ACK of SYN, otherwise only in a separate packet (but still // immediately) if (earlySend) sendRequest(); break; case MSGKIND_SEND: sendRequest(); numRequestsToSend--; // no scheduleAt(): next request will be sent when reply to this one // arrives (see socketDataArrived()) break; } }
void TCPBasicClientApp::initialize | ( | ) | [protected, virtual] |
Redefined to schedule a connect().
Reimplemented from TCPGenericCliAppBase.
Definition at line 38 of file TCPBasicClientApp.cc.
{ TCPGenericCliAppBase::initialize(); timeoutMsg = new cMessage("timer"); numRequestsToSend = 0; earlySend = false; // TBD make it parameter WATCH(numRequestsToSend); WATCH(earlySend); timeoutMsg->setKind(MSGKIND_CONNECT); scheduleAt((simtime_t)par("startTime"), timeoutMsg); }
void TCPBasicClientApp::sendRequest | ( | ) | [protected, virtual] |
Utility: sends a request to the server
Definition at line 53 of file TCPBasicClientApp.cc.
Referenced by handleTimer(), and socketEstablished().
{ EV << "sending request, " << numRequestsToSend-1 << " more to go\n"; long requestLength = par("requestLength"); long replyLength = par("replyLength"); if (requestLength<1) requestLength=1; if (replyLength<1) replyLength=1; sendPacket(requestLength, replyLength); }
void TCPBasicClientApp::socketClosed | ( | int | connId, | |
void * | yourPtr | |||
) | [protected, virtual] |
Redefined to start another session after a delay.
Reimplemented from TCPGenericCliAppBase.
Definition at line 120 of file TCPBasicClientApp.cc.
{ TCPGenericCliAppBase::socketClosed(connId, ptr); // start another session after a delay timeoutMsg->setKind(MSGKIND_CONNECT); scheduleAt(simTime()+(simtime_t)par("idleInterval"), timeoutMsg); }
void TCPBasicClientApp::socketDataArrived | ( | int | connId, | |
void * | yourPtr, | |||
cPacket * | msg, | |||
bool | urgent | |||
) | [protected, virtual] |
Redefined.
Reimplemented from TCPGenericCliAppBase.
Definition at line 103 of file TCPBasicClientApp.cc.
{ TCPGenericCliAppBase::socketDataArrived(connId, ptr, msg, urgent); if (numRequestsToSend>0) { EV << "reply arrived\n"; timeoutMsg->setKind(MSGKIND_SEND); scheduleAt(simTime()+(simtime_t)par("thinkTime"), timeoutMsg); } else { EV << "reply to last request arrived, closing session\n"; close(); } }
void TCPBasicClientApp::socketEstablished | ( | int | connId, | |
void * | yourPtr | |||
) | [protected, virtual] |
Redefined.
Reimplemented from TCPGenericCliAppBase.
Definition at line 89 of file TCPBasicClientApp.cc.
{ TCPGenericCliAppBase::socketEstablished(connId, ptr); // determine number of requests in this session numRequestsToSend = (long) par("numRequestsPerSession"); if (numRequestsToSend<1) numRequestsToSend=1; // perform first request if not already done (next one will be sent when reply arrives) if (!earlySend) sendRequest(); numRequestsToSend--; }
void TCPBasicClientApp::socketFailure | ( | int | connId, | |
void * | yourPtr, | |||
int | code | |||
) | [protected, virtual] |
Redefined to reconnect after a delay.
Reimplemented from TCPGenericCliAppBase.
Definition at line 129 of file TCPBasicClientApp.cc.
{ TCPGenericCliAppBase::socketFailure(connId, ptr, code); // reconnect after a delay timeoutMsg->setKind(MSGKIND_CONNECT); scheduleAt(simTime()+(simtime_t)par("reconnectInterval"), timeoutMsg); }
bool TCPBasicClientApp::earlySend [protected] |
Definition at line 28 of file TCPBasicClientApp.h.
Referenced by handleTimer(), initialize(), and socketEstablished().
int TCPBasicClientApp::numRequestsToSend [protected] |
Definition at line 29 of file TCPBasicClientApp.h.
Referenced by handleTimer(), initialize(), sendRequest(), socketDataArrived(), and socketEstablished().
cMessage* TCPBasicClientApp::timeoutMsg [protected] |
Definition at line 27 of file TCPBasicClientApp.h.
Referenced by initialize(), socketClosed(), socketDataArrived(), socketFailure(), TCPBasicClientApp(), and ~TCPBasicClientApp().