Visual Servoing Platform  version 3.3.0
vpNetwork Class Reference

#include <vpNetwork.h>

+ Inheritance diagram for vpNetwork:

Public Member Functions

 vpNetwork ()
 
virtual ~vpNetwork ()
 
void addDecodingRequest (vpRequest *)
 
int getReceptorIndex (const char *name)
 
std::string getRequestIdFromIndex (const int &ind)
 
unsigned int getMaxSizeReceivedMessage ()
 
void print (const char *id="")
 
template<typename T >
int receive (T *object, const unsigned int &sizeOfObject=sizeof(T))
 
template<typename T >
int receiveFrom (T *object, const unsigned int &receptorEmitting, const unsigned int &sizeOfObject=sizeof(T))
 
std::vector< int > receiveRequest ()
 
std::vector< int > receiveRequestFrom (const unsigned int &receptorEmitting)
 
int receiveRequestOnce ()
 
int receiveRequestOnceFrom (const unsigned int &receptorEmitting)
 
std::vector< int > receiveAndDecodeRequest ()
 
std::vector< int > receiveAndDecodeRequestFrom (const unsigned int &receptorEmitting)
 
int receiveAndDecodeRequestOnce ()
 
int receiveAndDecodeRequestOnceFrom (const unsigned int &receptorEmitting)
 
void removeDecodingRequest (const char *)
 
template<typename T >
int send (T *object, const int unsigned &sizeOfObject=sizeof(T))
 
template<typename T >
int sendTo (T *object, const unsigned int &dest, const unsigned int &sizeOfObject=sizeof(T))
 
int sendRequest (vpRequest &req)
 
int sendRequestTo (vpRequest &req, const unsigned int &dest)
 
int sendAndEncodeRequest (vpRequest &req)
 
int sendAndEncodeRequestTo (vpRequest &req, const unsigned int &dest)
 
void setMaxSizeReceivedMessage (const unsigned int &s)
 
void setTimeoutSec (const long &sec)
 
void setTimeoutUSec (const long &usec)
 
void setVerbose (const bool &mode)
 
template<typename T >
int send (T *object, const unsigned int &sizeOfObject)
 

Protected Attributes

vpEmitter emitter
 
std::vector< vpReceptor > receptor_list
 
fd_set readFileDescriptor
 
int socketMax
 
std::vector< vpRequest * > request_list
 
unsigned int max_size_message
 
std::string separator
 
std::string beginning
 
std::string end
 
std::string param_sep
 
std::string currentMessageReceived
 
struct timeval tv
 
long tv_sec
 
long tv_usec
 
bool verboseMode
 

Detailed Description

This class represents a Transmission Control Protocol (TCP) network.

TCP provides reliable, ordered delivery of a stream of bytes from a program on one computer to another program on another computer.

Warning
This class shouldn't be used directly. You better use vpClient and vpServer to simulate your network. Some exemples are provided in these classes.
See also
vpServer
vpNetwork

Definition at line 89 of file vpNetwork.h.

Constructor & Destructor Documentation

◆ vpNetwork()

vpNetwork::vpNetwork ( )

Definition at line 43 of file vpNetwork.cpp.

References tv, tv_sec, and tv_usec.

◆ ~vpNetwork()

vpNetwork::~vpNetwork ( )
virtual

Definition at line 64 of file vpNetwork.cpp.

Member Function Documentation

◆ addDecodingRequest()

void vpNetwork::addDecodingRequest ( vpRequest req)

Add a decoding request to the emitter. This request will be used to decode the received messages. Each request must have a different id.

Warning
vpRequest is a virtual pure class. It has to be implemented according to the way how you want to decode the message received.
See also
vpNetwork::removeDecodingRequest()
Parameters
req: Request to add.

Definition at line 82 of file vpNetwork.cpp.

◆ getMaxSizeReceivedMessage()

unsigned int vpNetwork::getMaxSizeReceivedMessage ( )
inline

Get the maximum size that the emitter can receive (in request mode).

See also
vpNetwork::setMaxSizeReceivedMessage()
Returns
Acutal max size value.

Definition at line 192 of file vpNetwork.h.

◆ getReceptorIndex()

int vpNetwork::getReceptorIndex ( const char *  name)

Get the receptor index from its name. The name can be either the IP, or its name on the network.

Parameters
name: Name of the receptor.
Returns
Index of the receptor, or -1 if an error occurs.

Definition at line 137 of file vpNetwork.cpp.

◆ getRequestIdFromIndex()

std::string vpNetwork::getRequestIdFromIndex ( const int &  ind)
inline

Get the Id of the request at the index ind.

Parameters
ind: Index of the request.
Returns
Id of the request.

Definition at line 178 of file vpNetwork.h.

◆ print()

void vpNetwork::print ( const char *  id = "")

Print the receptors.

Parameters
id: Message to display before the receptor's index.

Definition at line 122 of file vpNetwork.cpp.

◆ receive()

template<typename T >
int vpNetwork::receive ( T *  object,
const unsigned int &  sizeOfObject = sizeof(T) 
)

Receives a object. The size of the received object is suppose to be the size of the type of the object. Note that a received message can correspond to a deconnection signal.

Warning
Using this function means that you know what kind of object you are suppose to receive, and when you are suppose to receive. If the emitter has several receptors. It might be a problem, and in that case you better use the "request" option.
See also
vpNetwork::receiveRequest()
vpNetwork::receiveRequestOnce()
vpNetwork::receiveAndDecodeRequest()
vpNetwork::receiveAndDecodeRequestOnce()
Parameters
object: Received object.
sizeOfObject: Size of the received object.
Returns
the number of bytes received, or -1 if an error occured.
Examples
testClient.cpp, and testServer.cpp.

Definition at line 282 of file vpNetwork.h.

◆ receiveAndDecodeRequest()

std::vector< int > vpNetwork::receiveAndDecodeRequest ( )

◆ receiveAndDecodeRequestFrom()

std::vector< int > vpNetwork::receiveAndDecodeRequestFrom ( const unsigned int &  receptorEmitting)

Receives and decode requests, from a specific emitter, untils there is request to receive.

Warning
Requests will be received but not decoded.
See also
vpNetwork::receive()
vpNetwork::receiveRequest()
vpNetwork::receiveRequestOnce()
vpNetwork::receiveRequestOnceFrom()
vpNetwork::receiveAndDecodeRequest()
vpNetwork::receiveAndDecodeRequestFrom()
vpNetwork::receiveAndDecodeRequestOnce()
vpNetwork::receiveAndDecodeRequestOnceFrom()
Parameters
receptorEmitting: Index of the receptor emitting the message

Definition at line 401 of file vpNetwork.cpp.

◆ receiveAndDecodeRequestOnce()

int vpNetwork::receiveAndDecodeRequestOnce ( )

Receives a message once (in the limit of the Maximum message size value). This message can represent an entire request or not. Several calls to this function might be necessary to get the entire request. If it represents an entire request, it decodes the request.

Warning
Requests will be received but not decoded.
See also
vpNetwork::receive()
vpNetwork::receiveRequestFrom()
vpNetwork::receiveRequest()
vpNetwork::receiveRequestOnceFrom()
vpNetwork::receiveAndDecodeRequest()
vpNetwork::receiveAndDecodeRequestFrom()
vpNetwork::receiveAndDecodeRequestOnce()
vpNetwork::receiveAndDecodeRequestOnceFrom()
Returns
The number of bytes received, -1 if an error occured.

Definition at line 431 of file vpNetwork.cpp.

◆ receiveAndDecodeRequestOnceFrom()

int vpNetwork::receiveAndDecodeRequestOnceFrom ( const unsigned int &  receptorEmitting)

Receives a message once (in the limit of the Maximum message size value), from a specific emitter. This message can represent an entire request or not. Several calls to this function might be necessary to get the entire request. If it represents an entire request, it decodes the request.

Warning
Requests will be received but not decoded.
See also
vpNetwork::receive()
vpNetwork::receiveRequestFrom()
vpNetwork::receiveRequest()
vpNetwork::receiveRequestOnce()
vpNetwork::receiveAndDecodeRequest()
vpNetwork::receiveAndDecodeRequestFrom()
vpNetwork::receiveAndDecodeRequestOnce()
vpNetwork::receiveAndDecodeRequestOnceFrom()
Parameters
receptorEmitting: Index of the receptor emitting the message.
Returns
The number of bytes received, -1 if an error occured.

Definition at line 461 of file vpNetwork.cpp.

◆ receiveFrom()

template<typename T >
int vpNetwork::receiveFrom ( T *  object,
const unsigned int &  receptorEmitting,
const unsigned int &  sizeOfObject = sizeof(T) 
)

Receives a object from a receptor, by specifying its size or not. Note that a received message can correspond to a deconnection signal.

Warning
Using this function means that you know what kind of object you are suppose to receive, and when you are suppose to receive. If the emitter has several receptors. It might be a problem, and in that case you better use the "request" mode.
See also
vpNetwork::getReceptorIndex()
vpNetwork::receiveRequestFrom()
vpNetwork::receiveRequestOnceFrom()
vpNetwork::receiveAndDecodeRequestFrom()
vpNetwork::receiveAndDecodeRequestOnceFrom()
Parameters
object: Received object.
receptorEmitting: Index of the receptor emitting the message.
sizeOfObject: Size of the received object.
Returns
the number of bytes received, or -1 if an error occured.

Definition at line 364 of file vpNetwork.h.

References readFileDescriptor, receptor_list, socketMax, tv, tv_sec, tv_usec, verboseMode, vpERROR_TRACE, and vpTRACE.

◆ receiveRequest()

std::vector< int > vpNetwork::receiveRequest ( )

◆ receiveRequestFrom()

std::vector< int > vpNetwork::receiveRequestFrom ( const unsigned int &  receptorEmitting)

Receives requests, from a specific emitter, untils there is request to receive.

Warning
Requests will be received but not decoded.
See also
vpNetwork::receive()
vpNetwork::receiveRequest()
vpNetwork::receiveRequestOnce()
vpNetwork::receiveRequestOnceFrom()
vpNetwork::receiveAndDecodeRequest()
vpNetwork::receiveAndDecodeRequestFrom()
vpNetwork::receiveAndDecodeRequestOnce()
vpNetwork::receiveAndDecodeRequestOnceFrom()
Parameters
receptorEmitting: Index of the receptor emitting the message

Definition at line 303 of file vpNetwork.cpp.

◆ receiveRequestOnce()

int vpNetwork::receiveRequestOnce ( )

Receives a message once (in the limit of the Maximum message size value). This message can represent an entire request or not. Several calls to this function might be necessary to get the entire request.

Warning
Requests will be received but not decoded.
See also
vpNetwork::receive()
vpNetwork::receiveRequestFrom()
vpNetwork::receiveRequest()
vpNetwork::receiveRequestOnceFrom()
vpNetwork::receiveAndDecodeRequest()
vpNetwork::receiveAndDecodeRequestFrom()
vpNetwork::receiveAndDecodeRequestOnce()
vpNetwork::receiveAndDecodeRequestOnceFrom()
Returns
The number of bytes received, -1 if an error occured.

Definition at line 327 of file vpNetwork.cpp.

◆ receiveRequestOnceFrom()

int vpNetwork::receiveRequestOnceFrom ( const unsigned int &  receptorEmitting)

Receives a message once (in the limit of the Maximum message size value), from a specific emitter. This message can represent an entire request or not. Several calls to this function might be necessary to get the entire request.

Warning
Requests will be received but not decoded.
See also
vpNetwork::receive()
vpNetwork::receiveRequestFrom()
vpNetwork::receiveRequest()
vpNetwork::receiveRequestOnce()
vpNetwork::receiveAndDecodeRequest()
vpNetwork::receiveAndDecodeRequestFrom()
vpNetwork::receiveAndDecodeRequestOnce()
vpNetwork::receiveAndDecodeRequestOnceFrom()
Parameters
receptorEmitting: Index of the receptor emitting the message.
Returns
The number of bytes received, -1 if an error occured.

Definition at line 354 of file vpNetwork.cpp.

◆ removeDecodingRequest()

void vpNetwork::removeDecodingRequest ( const char *  id)

Delete a decoding request from the emitter.

See also
vpNetwork::addDecodingRequest()
Parameters
id: Id of the request to delete.

Definition at line 107 of file vpNetwork.cpp.

◆ send() [1/2]

template<typename T >
int vpNetwork::send ( T *  object,
const int unsigned &  sizeOfObject = sizeof(T) 
)

◆ send() [2/2]

template<typename T >
int vpNetwork::send ( T *  object,
const unsigned int &  sizeOfObject 
)

Send an object. The size of the received object is suppose to be the size of its type. Note that sending object containing pointers, virtual methods, etc, won't probably work.

Warning
Using this function means that, in the other side of the network, it knows what kind of object it is suppose to receive, and when it is suppose to receive. If the emitter has several receptors. It might be a problem, and in that case you better use the "request" option.
See also
vpNetwork::sendTo()
vpNetwork::sendRequest()
vpNetwork::sendRequestTo()
vpNetwork::sendAndEncodeRequest()
vpNetwork::sendAndEncodeRequestTo()
Parameters
object: Received object.
sizeOfObject: Size of the object
Returns
The number of bytes sent, or -1 if an error happened.

Definition at line 436 of file vpNetwork.h.

◆ sendAndEncodeRequest()

int vpNetwork::sendAndEncodeRequest ( vpRequest req)

Send and encode a request to the first receptor in the list.

See also
vpNetwork::sendRequestTo()
vpNetwork::sendAndEncodeRequest()
vpNetwork::sendAndEncodeRequestTo()
vpNetwork::send()
vpNetwork::sendTo()
Parameters
req: Request to send.
Returns
The number of bytes that have been sent, -1 if an error occured.

Definition at line 240 of file vpNetwork.cpp.

◆ sendAndEncodeRequestTo()

int vpNetwork::sendAndEncodeRequestTo ( vpRequest req,
const unsigned int &  dest 
)

Send and encode a request to a specific receptor.

See also
vpNetwork::sendRequest()
vpNetwork::sendAndEncodeRequest()
vpNetwork::sendAndEncodeRequestTo()
vpNetwork::send()
vpNetwork::sendTo()
Parameters
req: Request to send.
dest: Index of the receptor receiving the request.
Returns
The number of bytes that have been sent, -1 if an error occured.

Definition at line 260 of file vpNetwork.cpp.

◆ sendRequest()

int vpNetwork::sendRequest ( vpRequest req)

Send a request to the first receptor in the list.

See also
vpNetwork::sendRequestTo()
vpNetwork::sendAndEncodeRequest()
vpNetwork::sendAndEncodeRequestTo()
vpNetwork::send()
vpNetwork::sendTo()
Parameters
req: Request to send.
Returns
The number of bytes that have been sent, -1 if an error occured.

Definition at line 172 of file vpNetwork.cpp.

◆ sendRequestTo()

int vpNetwork::sendRequestTo ( vpRequest req,
const unsigned int &  dest 
)

Send a request to a specific receptor.

See also
vpNetwork::sendRequest()
vpNetwork::sendAndEncodeRequest()
vpNetwork::sendAndEncodeRequestTo()
vpNetwork::send()
vpNetwork::sendTo()
Parameters
req: Request to send.
dest: Index of the receptor receiving the request.
Returns
The number of bytes that have been sent, -1 if an error occured.

Definition at line 188 of file vpNetwork.cpp.

◆ sendTo()

template<typename T >
int vpNetwork::sendTo ( T *  object,
const unsigned int &  dest,
const unsigned int &  sizeOfObject = sizeof(T) 
)

Send an object. The size has to be specified.

Warning
Using this function means that, in the other side of the network, it knows what kind of object it is suppose to receive, and when it is suppose to receive. If the emitter has several receptors. It might be a problem, and in that case you better use the "request" option.
See also
vpNetwork::getReceptorIndex()
vpNetwork::send()
vpNetwork::sendRequest()
vpNetwork::sendRequestTo()
vpNetwork::sendAndEncodeRequest()
vpNetwork::sendAndEncodeRequestTo()
Parameters
object: Object to send.
dest: Index of the receptor that you are sending the object.
sizeOfObject: Size of the object.
Returns
The number of bytes sent, or -1 if an error happened.

Definition at line 480 of file vpNetwork.h.

◆ setMaxSizeReceivedMessage()

void vpNetwork::setMaxSizeReceivedMessage ( const unsigned int &  s)
inline

Change the maximum size that the emitter can receive (in request mode).

See also
vpNetwork::getMaxSizeReceivedMessage()
Parameters
s: new maximum size value.

Definition at line 228 of file vpNetwork.h.

◆ setTimeoutSec()

void vpNetwork::setTimeoutSec ( const long &  sec)
inline

Change the time the emitter spend to check if he receives a message from a receptor. Initially this value is set to 10usec.

See also
vpNetwork::setTimeoutUSec()
Parameters
sec: new value in second.

Definition at line 238 of file vpNetwork.h.

◆ setTimeoutUSec()

void vpNetwork::setTimeoutUSec ( const long &  usec)
inline

Change the time the emitter spend to check if he receives a message from a receptor. Initially this value is set to 10usec.

See also
vpNetwork::setTimeoutSec()
Parameters
usec: new value in micro second.

Definition at line 248 of file vpNetwork.h.

◆ setVerbose()

void vpNetwork::setVerbose ( const bool &  mode)
inline

Set the verbose mode.

Parameters
mode: Change the verbose mode. True to turn on, False to turn off.

Definition at line 255 of file vpNetwork.h.

Member Data Documentation

◆ beginning

std::string vpNetwork::beginning
protected

Definition at line 142 of file vpNetwork.h.

◆ currentMessageReceived

std::string vpNetwork::currentMessageReceived
protected

Definition at line 146 of file vpNetwork.h.

◆ emitter

vpEmitter vpNetwork::emitter
protected

Definition at line 128 of file vpNetwork.h.

◆ end

std::string vpNetwork::end
protected

Definition at line 143 of file vpNetwork.h.

◆ max_size_message

unsigned int vpNetwork::max_size_message
protected

Definition at line 140 of file vpNetwork.h.

◆ param_sep

std::string vpNetwork::param_sep
protected

Definition at line 144 of file vpNetwork.h.

◆ readFileDescriptor

fd_set vpNetwork::readFileDescriptor
protected

Definition at line 130 of file vpNetwork.h.

Referenced by receiveFrom().

◆ receptor_list

std::vector<vpReceptor> vpNetwork::receptor_list
protected

Definition at line 129 of file vpNetwork.h.

Referenced by receiveFrom().

◆ request_list

std::vector<vpRequest *> vpNetwork::request_list
protected

Definition at line 138 of file vpNetwork.h.

◆ separator

std::string vpNetwork::separator
protected

Definition at line 141 of file vpNetwork.h.

◆ socketMax

int vpNetwork::socketMax
protected

Definition at line 132 of file vpNetwork.h.

Referenced by receiveFrom().

◆ tv

struct timeval vpNetwork::tv
protected

Definition at line 148 of file vpNetwork.h.

Referenced by receiveFrom(), and vpNetwork().

◆ tv_sec

long vpNetwork::tv_sec
protected

Definition at line 149 of file vpNetwork.h.

Referenced by receiveFrom(), and vpNetwork().

◆ tv_usec

long vpNetwork::tv_usec
protected

Definition at line 150 of file vpNetwork.h.

Referenced by receiveFrom(), and vpNetwork().

◆ verboseMode

bool vpNetwork::verboseMode
protected

Definition at line 152 of file vpNetwork.h.

Referenced by receiveFrom().