C++ IP API  9.5.7
TCP & UDP for virtual user scripts
Facilita::TcpConnection Class Reference

A TCP protocol connection endpoint that manages an underlying socket. Provides methods for sending and receiving data that are designed for use in test scripts More...

Inheritance diagram for Facilita::TcpConnection:
Collaboration diagram for Facilita::TcpConnection:

Public Methods

 TcpConnection ()
 Default constructor (not called directly by user written code). More...
 
 TcpConnection (const TcpConnection &other)
 Copy constructor. More...
 
int getConnectRetries () const
 Get the number of times a connection request will be retried if unsuccessful. More...
 
TcpConnectionoperator= (const TcpConnection &other)
 Assignment operator. More...
 
void setConnectRetries (int retries)
 Set the number of times a connection request will be retried if unsuccessful. More...
 
Public Methods For Connecting, Sending And Receiving Data
void disconnect (ActionType failAction=ACT_RAISE_EXCEPTION)
 
void send (const string &text, int reference=0, ActionType failAction=ACT_RAISE_EXCEPTION)
 Send data string. More...
 
ReceiveResponse receive (int nBytes, ActionType failAction=ACT_RAISE_EXCEPTION)
 Receive (read and return) a specified number of bytes. More...
 
ReceiveResponse receive (const string &text, ActionType failAction=ACT_RAISE_EXCEPTION)
 Receive (read and return) data up to and including the string argument to this method, but no more than the maximum stipulated in the property Buffersize. A call will terminate with an error if the target string has not been matched within the time period defined by the property ReceiveTimeout. This method will only read up to a maximum number of bytes set in the property Buffersize and will indicate an error if the match has not occurred. More...
 
PatternResponse receive (Pattern &pattern, ActionType failAction=ACT_RAISE_EXCEPTION)
 Receive (read and return) a string of bytes up to and including the pattern specified. This method will only read up to a maximum number of bytes set in the property Buffersize. A call will terminate with an error if the match has not occurred within the time period defined by the property ReceiveTimeout. More...
 
PatternResponse unblockedReceive (Pattern &pattern, ActionType failAction=ACT_RAISE_EXCEPTION)
 Receive (return) a string of bytes up to and including the pattern specified from data already read from the underling socket. More...
 
int clearBuffer ()
 Clear (throw away) all data currently held for this connection. No read from the underlying socket is made by this call. More...
 
DiscardResponse discardUpto (const string &text, ActionType failAction=ACT_RAISE_EXCEPTION)
 Discard (read and throw away) bytes up to and including the string specified. More...
 
DiscardResponse discardUpto (Pattern &pattern, ActionType failAction=ACT_RAISE_EXCEPTION)
 Discard (read and throw away) bytes up to and including the pattern specified. More...
 
DiscardResponse discard (int nBytes, ActionType failAction=ACT_RAISE_EXCEPTION)
 Discard (read and throw away) a specific number of bytes of data. Data may be read from the underlying communications layer. More...
 
DiscardResponse discardForTimePeriod (long millis, ActionType failAction=ACT_RAISE_EXCEPTION)
 Read and throwaway bytes all data received within the given time. This includes any data that is already held by this connection. More...
 
int getBufferSize () const
 Get the size of the buffer used to receive data from the network. More...
 
void setBufferSize (int bufferSize)
 Set the current buffer size. More...
 
int getDnsTimeout () const
 Get the DNS look up timeout value (the maximum time that will be spent looking up an IP address). More...
 
void setDnsTimeout (int timeout)
 Set the DNS look up timeout value (the maximum time that will be spent looking up an IP address). More...
 
int getDnsRetries () const
 Get the number of times a DNS lookup is attempted before giving up. More...
 
void setDnsRetries (int retries)
 Set the number of DNS lookup retries that can be made. More...
 
int getReceiveTimeout () const
 Get the the maximum time to be spent waiting for data to satisfy a receive/discard request More...
 
void setReceiveTimeout (int timeout)
 Set the receive timeout. More...
 
int getConnectTimeout () const
 Get the maximum time to be spent waiting for the response to a connection request. More...
 
void setConnectTimeout (int timeout)
 Set the maximum time to be spent waiting for the response to a connection request. More...
 
bool isLoggingEnabled () const
 Read only, indicates if logging is enabled. More...
 
int getSendTimeout () const
 Get the timeout used whilst waiting for data to be sent. More...
 
void setSendTimeout (int timeout)
 Set the send timeout. More...
 
DataRatePacer & getDataRate () const
 Get the maximum rate (kilobits per second) at which data will be transferred over this connection. A negative value or 0 means no limit. This feature provides a basic and unsophisticated way of simulating traffic over slow networks and this type of simulation is no match for dedicated network simulation tools. More...
 
void setDataRate (int dataRate)
 Set the maximum rate (kilobits per second) at which data will be transferred over this connection. A negative value or 0 means no limit. This feature provides a basic and unsophisticated way of simulating traffic over slow networks and this type of simulation is no match for dedicated network simulation tools. More...
 
IpEndPoint getRemoteIpEndPoint () const
 Get the remote IpEndPoint. More...
 
IpEndPoint getLocalIpEndPoint () const
 Get the local IpEndPoint. More...
 
void suspendLogging ()
 
void resumeLogging ()
 
string toString () const
 A short string describing this object. More...
 
int getConnectionNumber ()
 Get the connection number. More...
 

Detailed Description

A TCP protocol connection endpoint that manages an underlying socket. Provides methods for sending and receiving data that are designed for use in test scripts

TcpConnection objects are not created directly, use IpScript or IpVirtualUser factory methods.

Objects of this class can be copied and re-assigned. They are not thread-safe.

Constructors

Facilita::TcpConnection::TcpConnection ( )

Default constructor (not called directly by user written code).

Facilita::TcpConnection::TcpConnection ( const TcpConnection other)

Copy constructor.

Methods

int Facilita::TcpConnection::clearBuffer ( )

Clear (throw away) all data currently held for this connection. No read from the underlying socket is made by this call.

Returns
The number of bytes cleared.
DiscardResponse Facilita::TcpConnection::discard ( int  nBytes,
ActionType  failAction = ACT_RAISE_EXCEPTION 
)

Discard (read and throw away) a specific number of bytes of data. Data may be read from the underlying communications layer.

Parameters
nBytesThe number of bytes to discard.
failActionAction to be taken on failure. It is reported as a failure if fewer bytes are discarded than requested.
Returns
A DiscardResponse.
DiscardResponse Facilita::TcpConnection::discardForTimePeriod ( long  millis,
ActionType  failAction = ACT_RAISE_EXCEPTION 
)

Read and throwaway bytes all data received within the given time. This includes any data that is already held by this connection.

Parameters
millistime in milliseconds to read and discard data.
failActionAction to be taken on failure.
Returns
A DiscardResponse.
DiscardResponse Facilita::TcpConnection::discardUpto ( const string &  text,
ActionType  failAction = ACT_RAISE_EXCEPTION 
)

Discard (read and throw away) bytes up to and including the string specified.

Parameters
textThe string to match the end of the data to be discarded.
failActionAction to be taken on failure.
Returns
A DiscardResponse.
DiscardResponse Facilita::TcpConnection::discardUpto ( Pattern pattern,
ActionType  failAction = ACT_RAISE_EXCEPTION 
)

Discard (read and throw away) bytes up to and including the pattern specified.

Parameters
patternA pattern object to match the end of the data to be discarded.
failActionAction to be taken on failure.
Returns
A DiscardResponse.
void Facilita::TcpConnection::disconnect ( ActionType  failAction = ACT_RAISE_EXCEPTION)

Disconnect this connection. If the TcpConnection is not connected then this method does nothing.

Parameters
failActionAction to be taken on failure.
int Facilita::TcpConnection::getBufferSize ( ) const

Get the size of the buffer used to receive data from the network.

Returns
The current buffer size.
int Facilita::TcpConnection::getConnectionNumber ( )

Get the connection number.

Returns
Return the unique connection number identifying this connection.
int Facilita::TcpConnection::getConnectRetries ( ) const

Get the number of times a connection request will be retried if unsuccessful.

Returns
The current number of retries.
int Facilita::TcpConnection::getConnectTimeout ( ) const

Get the maximum time to be spent waiting for the response to a connection request.

Returns
The current timeout in milliseconds.
DataRatePacer& Facilita::TcpConnection::getDataRate ( ) const

Get the maximum rate (kilobits per second) at which data will be transferred over this connection. A negative value or 0 means no limit. This feature provides a basic and unsophisticated way of simulating traffic over slow networks and this type of simulation is no match for dedicated network simulation tools.

Returns
A reference to the current DataRatePacer.
int Facilita::TcpConnection::getDnsRetries ( ) const

Get the number of times a DNS lookup is attempted before giving up.

Returns
The current maximum number of retries that can be made.
int Facilita::TcpConnection::getDnsTimeout ( ) const

Get the DNS look up timeout value (the maximum time that will be spent looking up an IP address).

Returns
The timeout value in milliseconds.
IpEndPoint Facilita::TcpConnection::getLocalIpEndPoint ( ) const

Get the local IpEndPoint.

Returns
The local IpEndPoint.
int Facilita::TcpConnection::getReceiveTimeout ( ) const

Get the the maximum time to be spent waiting for data to satisfy a receive/discard request

Returns
The current timeout in milliseconds.
IpEndPoint Facilita::TcpConnection::getRemoteIpEndPoint ( ) const

Get the remote IpEndPoint.

Returns
The remote IpEndPoint.
int Facilita::TcpConnection::getSendTimeout ( ) const

Get the timeout used whilst waiting for data to be sent.

Returns
The current timeout.
bool Facilita::TcpConnection::isLoggingEnabled ( ) const

Read only, indicates if logging is enabled.

Returns
True if logging enabled else false.
TcpConnection& Facilita::TcpConnection::operator= ( const TcpConnection other)

Assignment operator.

Returns
The this object.
ReceiveResponse Facilita::TcpConnection::receive ( int  nBytes,
ActionType  failAction = ACT_RAISE_EXCEPTION 
)

Receive (read and return) a specified number of bytes.

The bytes read will not exceed the lesser of property Buffersize and the nBytes parameter. A call will terminate with an error if the full quota of bytes cannot be read within the time period defined by the property ReceiveTimeout.

Parameters
nBytesThe number of bytes to attempt to read.
failActionAction to be taken on failure.
Returns
A ReceiveResponse.
ReceiveResponse Facilita::TcpConnection::receive ( const string &  text,
ActionType  failAction = ACT_RAISE_EXCEPTION 
)

Receive (read and return) data up to and including the string argument to this method, but no more than the maximum stipulated in the property Buffersize. A call will terminate with an error if the target string has not been matched within the time period defined by the property ReceiveTimeout. This method will only read up to a maximum number of bytes set in the property Buffersize and will indicate an error if the match has not occurred.

Parameters
textThe string to match within the data.
failActionAction to be taken on failure.
Returns
A ReceiveResponse.
PatternResponse Facilita::TcpConnection::receive ( Pattern pattern,
ActionType  failAction = ACT_RAISE_EXCEPTION 
)

Receive (read and return) a string of bytes up to and including the pattern specified. This method will only read up to a maximum number of bytes set in the property Buffersize. A call will terminate with an error if the match has not occurred within the time period defined by the property ReceiveTimeout.

Parameters
patternA pattern object to match within the read data stream.
failActionAction to be taken on failure.
Returns
A ReceiveResponse.
void Facilita::TcpConnection::resumeLogging ( )
void Facilita::TcpConnection::send ( const string &  text,
int  reference = 0,
ActionType  failAction = ACT_RAISE_EXCEPTION 
)

Send data string.

Parameters
textThe data.
referenceA number to tag the call when logging the conversation.
failActionAction to be taken on failure.
void Facilita::TcpConnection::setBufferSize ( int  bufferSize)

Set the current buffer size.

Parameters
bufferSizeThe number of bytes to set the buffer size.
void Facilita::TcpConnection::setConnectRetries ( int  retries)

Set the number of times a connection request will be retried if unsuccessful.

Parameters
retriesSet this number of retries.
void Facilita::TcpConnection::setConnectTimeout ( int  timeout)

Set the maximum time to be spent waiting for the response to a connection request.

Parameters
timeoutThe timeout value in milliseconds.
void Facilita::TcpConnection::setDataRate ( int  dataRate)

Set the maximum rate (kilobits per second) at which data will be transferred over this connection. A negative value or 0 means no limit. This feature provides a basic and unsophisticated way of simulating traffic over slow networks and this type of simulation is no match for dedicated network simulation tools.

Parameters
dataRateThe rate expressed as kilobits per second.
void Facilita::TcpConnection::setDnsRetries ( int  retries)

Set the number of DNS lookup retries that can be made.

Parameters
retriesThe number retries that can be made on a DNS look up.
void Facilita::TcpConnection::setDnsTimeout ( int  timeout)

Set the DNS look up timeout value (the maximum time that will be spent looking up an IP address).

Parameters
timeoutThe DNS look up timeout in milliseconds.
void Facilita::TcpConnection::setReceiveTimeout ( int  timeout)

Set the receive timeout.

Parameters
timeoutThe timeout value in milliseconds.
void Facilita::TcpConnection::setSendTimeout ( int  timeout)

Set the send timeout.

Parameters
timeoutThe new timeout value in milliseconds.
void Facilita::TcpConnection::suspendLogging ( )
string Facilita::TcpConnection::toString ( ) const

A short string describing this object.

Returns
The string describing this object.
PatternResponse Facilita::TcpConnection::unblockedReceive ( Pattern pattern,
ActionType  failAction = ACT_RAISE_EXCEPTION 
)

Receive (return) a string of bytes up to and including the pattern specified from data already read from the underling socket.

Unlike the other receive methods this variant will not block reading data from the underlying socket. This call should be made when it is known or expected that the data has been sent by the remote peer.

Parameters
patternA pattern object to match within the read data stream.
failActionAction to be taken on failure.
Returns
A PatternResponse.

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