#include <TCPGenericCliAppBase.h>
Inheritance diagram for TCPGenericCliAppBase:
It needs the following NED parameters: address, port, connectAddress, connectPort.
Generally used together with GenericAppMsg and TCPGenericSrvApp.
Protected Member Functions | |
virtual void | initialize () |
virtual void | handleMessage (cMessage *msg) |
virtual void | finish () |
virtual void | handleTimer (cMessage *msg)=0 |
Utility functions | |
virtual void | connect () |
virtual void | close () |
virtual void | sendPacket (int numBytes, int expectedReplyBytes, bool serverClose=false) |
virtual void | setStatusString (const char *s) |
TCPSocket::CallbackInterface callback methods | |
virtual void | socketEstablished (int connId, void *yourPtr) |
virtual void | socketDataArrived (int connId, void *yourPtr, cMessage *msg, bool urgent) |
virtual void | socketPeerClosed (int connId, void *yourPtr) |
virtual void | socketClosed (int connId, void *yourPtr) |
virtual void | socketFailure (int connId, void *yourPtr, int code) |
virtual void | socketStatusArrived (int connId, void *yourPtr, TCPStatusInfo *status) |
Protected Attributes | |
TCPSocket | socket |
int | numSessions |
int | numBroken |
int | packetsSent |
int | packetsRcvd |
int | bytesSent |
int | bytesRcvd |
|
Issues CLOSE command 00068 { 00069 setStatusString("closing"); 00070 EV << "issuing CLOSE command\n"; 00071 socket.close(); 00072 }
|
|
Issues an active OPEN to the address/port given as module parameters 00051 { 00052 // we need a new connId if this is not the first connection 00053 socket.renewSocket(); 00054 00055 // connect 00056 const char *connectAddress = par("connectAddress"); 00057 int connectPort = par("connectPort"); 00058 00059 EV << "issuing OPEN command\n"; 00060 setStatusString("connecting"); 00061 00062 socket.connect(IPAddressResolver().resolve(connectAddress), connectPort); 00063 00064 numSessions++; 00065 }
|
|
Records basic statistics: numSessions, packetsSent, packetsRcvd, bytesSent, bytesRcvd. Redefine to record different or more statistics at the end of the simulation. 00137 { 00138 EV << fullPath() << ": opened " << numSessions << " sessions\n"; 00139 EV << fullPath() << ": sent " << bytesSent << " bytes in " << packetsSent << " packets\n"; 00140 EV << fullPath() << ": received " << bytesRcvd << " bytes in " << packetsRcvd << " packets\n"; 00141 00142 recordScalar("number of sessions", numSessions); 00143 recordScalar("packets sent", packetsSent); 00144 recordScalar("packets rcvd", packetsRcvd); 00145 recordScalar("bytes sent", bytesSent); 00146 recordScalar("bytes rcvd", bytesRcvd); 00147 }
|
|
For self-messages it invokes handleTimer(); messages arriving from TCP will get dispatched to the socketXXX() functions. 00043 { 00044 if (msg->isSelfMessage()) 00045 handleTimer(msg); 00046 else 00047 socket.processMessage(msg); 00048 }
|
|
Invoked from handleMessage(). Should be redefined to handle self-messages. Implemented in TCPBasicClientApp, and TelnetApp. |
|
Initialization. Should be redefined to perform or schedule a connect(). Reimplemented in TCPBasicClientApp, and TelnetApp. 00022 { 00023 numSessions = numBroken = packetsSent = packetsRcvd = bytesSent = bytesRcvd = 0; 00024 WATCH(numSessions); 00025 WATCH(numBroken); 00026 WATCH(packetsSent); 00027 WATCH(packetsRcvd); 00028 WATCH(bytesSent); 00029 WATCH(bytesRcvd); 00030 00031 // parameters 00032 const char *address = par("address"); 00033 int port = par("port"); 00034 socket.bind(*address ? IPvXAddress(address) : IPvXAddress(), port); 00035 00036 socket.setCallbackObject(this); 00037 socket.setOutputGate(gate("tcpOut")); 00038 00039 setStatusString("waiting"); 00040 }
|
|
Sends a GenericAppMsg of the given length 00075 { 00076 EV << "sending " << numBytes << " bytes, expecting " << expectedReplyBytes << (serverClose ? ", and server should close afterwards\n" : "\n"); 00077 00078 GenericAppMsg *msg = new GenericAppMsg("data"); 00079 msg->setByteLength(numBytes); 00080 msg->setExpectedReplyLength(expectedReplyBytes); 00081 msg->setClose(serverClose); 00082 00083 socket.send(msg); 00084 00085 packetsSent++; 00086 bytesSent+=numBytes; 00087 }
|
|
When running under GUI, it displays the given string next to the icon 00090 { 00091 if (ev.isGUI()) displayString().setTagArg("t", 0, s); 00092 }
|
|
Does nothing but update statistics/status. Redefine if you want to do something else, such as opening a new connection. Reimplemented from TCPSocket::CallbackInterface. Reimplemented in TCPBasicClientApp, and TelnetApp. 00121 { 00122 // *redefine* to start another session etc. 00123 EV << "connection closed\n"; 00124 setStatusString("closed"); 00125 }
|
|
Does nothing but update statistics/status. Redefine to perform or schedule next sending. Beware: this funcion deletes the incoming message, which might not be what you want. Implements TCPSocket::CallbackInterface. Reimplemented in TCPBasicClientApp, and TelnetApp. 00102 { 00103 // *redefine* to perform or schedule next sending 00104 packetsRcvd++; 00105 bytesRcvd+=msg->byteLength(); 00106 00107 delete msg; 00108 }
|
|
Does nothing but update statistics/status. Redefine to perform or schedule first sending. Reimplemented from TCPSocket::CallbackInterface. Reimplemented in TCPBasicClientApp, and TelnetApp. 00095 { 00096 // *redefine* to perform or schedule first sending 00097 EV << "connected\n"; 00098 setStatusString("connected"); 00099 }
|
|
Does nothing but update statistics/status. Redefine if you want to try reconnecting after a delay. Reimplemented from TCPSocket::CallbackInterface. Reimplemented in TCPBasicClientApp, and TelnetApp. 00128 { 00129 // subclasses may override this function, and add code try to reconnect after a delay. 00130 EV << "connection broken\n"; 00131 setStatusString("broken"); 00132 00133 numBroken++; 00134 }
|
|
Since remote TCP closed, invokes close(). Redefine if you want to do something else. Reimplemented from TCPSocket::CallbackInterface. 00111 { 00112 // close the connection (if not already closed) 00113 if (socket.state()==TCPSocket::PEER_CLOSED) 00114 { 00115 EV << "remote TCP closed, closing here as well\n"; 00116 close(); 00117 } 00118 }
|
|
Redefine to handle incoming TCPStatusInfo. Reimplemented from TCPSocket::CallbackInterface. 00100 {delete status;}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|