Flair
Framework Libre Air
|
Class encapsulating a UDP socket. It assumes packets are coming from only one distant host on a given port. More...
#include <Socket.h>
Public Member Functions | |
Socket (const Object *parent, std::string name, std::string address, bool broadcast=false) | |
Constructor. More... | |
Socket (const Object *parent, std::string name, uint16_t port) | |
Constructor. More... | |
~Socket () | |
Destructor. More... | |
void | SendMessage (std::string message) |
Send a message. More... | |
void | SendMessage (const char *message, size_t message_len) |
Send a message. More... | |
ssize_t | RecvMessage (char *buf, size_t buf_len, Time timeout, char *src=NULL, size_t *src_len=NULL) |
Receive a message. More... | |
void | NetworkToHost (char *data, size_t dataSize) |
void | HostToNetwork (char *data, size_t dataSize) |
Public Member Functions inherited from flair::core::Object | |
Object (const Object *parent=NULL, std::string name="", std::string type="") | |
Constructor. More... | |
virtual | ~Object () |
Destructor. More... | |
std::string | ObjectName (void) const |
Name. More... | |
std::string | ObjectType (void) const |
Type. More... | |
const Object * | Parent (void) const |
Parent. More... | |
std::vector< const Object * > * | TypeChilds (void) const |
Childs of the same type. More... | |
std::vector< const Object * > * | Childs (void) const |
Childs. More... | |
void | Information (const char *function, int line, const char *format,...) const |
Formatted information. More... | |
void | Warning (const char *function, const char *format,...) const |
Formatted warning. More... | |
void | Error (const char *function, const char *format,...) const |
Formatted error. More... | |
bool | ErrorOccured (bool recursive=true) const |
Has an errror occured? More... | |
Additional Inherited Members | |
Public Types inherited from flair::core::Object | |
enum | color_t { Auto = 0, Red = 31, Green = 32, Orange = 33 } |
Class encapsulating a UDP socket. It assumes packets are coming from only one distant host on a given port.
flair::core::Socket::Socket | ( | const Object * | parent, |
std::string | name, | ||
std::string | address, | ||
bool | broadcast = false |
||
) |
Constructor.
Construct the client side of the socket
parent | parent |
name | name |
address | server address (ex 192.168.1.1:9000) |
broadcast | true if address is a broadcast address |
flair::core::Socket::Socket | ( | const Object * | parent, |
std::string | name, | ||
uint16_t | port | ||
) |
Constructor.
Construct the server side of the socket
parent | parent |
name | name |
port | listening port |
flair::core::Socket::~Socket | ( | ) |
Destructor.
void flair::core::Socket::SendMessage | ( | std::string | message | ) |
Send a message.
In case of a broadcast Socket, Parent()->ObjectName() is used as source of the message, this name should be unique.
message | message |
void flair::core::Socket::SendMessage | ( | const char * | message, |
size_t | message_len | ||
) |
Send a message.
message | message |
message_len | message length |
ssize_t flair::core::Socket::RecvMessage | ( | char * | buf, |
size_t | buf_len, | ||
Time | timeout, | ||
char * | src = NULL , |
||
size_t * | src_len = NULL |
||
) |
Receive a message.
Receive a message and wait up to timeout.
If src and src_len are specified, the source of the message will be copied in the src buffer.
Note that in case of a broadcast socket, own messages are filtered and are not received.
buf | buffer to put the message |
buf_len | buffer length |
timeout | timeout |
src | buffer to put source name |
src_len | buffer length |