This is the base class and interface definition for all communicators like the SteereoSocketCommunicator. The Communicators are used to accept connections to clients (or connect to simulations if you are the client) and sending data between simulation and client.
This are the functions you have to implement in your own communicator:
ssize_t writen(SteereoSingleConnection* fd, const void *vptr, size_t n)
ssize_t writen(SteereoSingleConnection* fd, const char* ptr, size_t n, int flags)
Specify how n bytes of the data pointed to from vptr or ptr are written over the connection fd.
ssize_t readn(SteereoSingleConnection* fd, void *vptr, size_t n)
ssize_t readn(SteereoSingleConnection* fd, char *ptr, size_t n, int flags)
Specify how n bytes of the data can be read from the connection fd to the memory pointed at by vptr or ptr.
int startConnection (SteereoSingleConnection** partner, const std::string ip, std::string connPort)
Specify how to connect to ip at “port” connPort and return a adequate SteereoSingleConnection which identifies the connection. The semantic of the last two parameters can of course vary with the type of the communicator. For example with MPI you wouldn't use the ip parameter and the connPort would be some previously published string.
SteereoSingleConnection* startListening (std::string listenPort)
With this function you would listen for incoming data at port listenPort (usually you will do that in simulations) and return the adequate “connection”.
void acceptConnection(SteereoSingleConnection* listenfd, SteereoSingleConnection** acceptfd)
Specify here how to accept incoming connections given the listening “connection” and return the connection data in acceptfd.
The functions startConnection, startListening and acceptConnection from above are of course also needed for the daily usage of communicators. Other than that you will do communication with these functions, which are based on the ones in the previous section:
void sendStream (SteereoSingleConnection* dest, SteereoStream& stream, steereoCompression* compression=NULL)
void receiveStream (SteereoSingleConnection* src, SteereoStream* stream, steereoCompression* compression=NULL)
send/receive the SteereoStream stream which may be compressed using the SteereoCompressioncompression over the connection dest / src.
void sendString (SteereoSingleConnection* dest, std::string request)
void sendInteger (SteereoSingleConnection* dest, int data)
void sendDouble (SteereoSingleConnection* dest, double data)
void receiveString (SteereoSingleConnection* src, std::string* data)
void receiveInteger (SteereoSingleConnection* src, int* data)
void receiveDouble (SteereoSingleConnection* src, double *d)
sending/receiving strings or integer or doubles. May be used when you really want to send/receive only one value. Otherwise you should use a SteereoStream and use the functions above.