Flair
Framework Libre Air
flair::core::TcpSocket Class Reference

Class encapsulating a TCP socket. More...

#include <TcpSocket.h>

+ Inheritance diagram for flair::core::TcpSocket:

Public Member Functions

 TcpSocket (const Object *parent, const std::string name, bool blockOnSend=false, bool blockOnReceive=true)
 
void Listen (const unsigned int port, const std::string localAddress="ANY")
 Returns a socket which listens on a specific port/address. More...
 
TcpSocketAccept (Time timeout=0)
 Returns a socket on a new incoming connexion. More...
 
bool Connect (const unsigned int distantPort, const std::string distantAddress, Time timeout=0)
 Returns a socket connected to a distant host. More...
 
ssize_t SendMessage (const char *message, size_t message_len, Time timeout=0)
 Send a message. More...
 
ssize_t RecvMessage (char *buf, size_t buf_len, Time timeout=0)
 Receive a message. More...
 
uint16_t NetworkToHost16 (uint16_t data)
 ! See Socket.h for a more generic implementation of network/host endianness More...
 
uint16_t HostToNetwork16 (uint16_t data)
 
uint32_t NetworkToHost32 (uint32_t data)
 
uint32_t HostToNetwork32 (uint32_t data)
 
- Public Member Functions inherited from flair::core::ConnectedSocket
 ConnectedSocket (const Object *parent, const std::string name)
 Constructor. More...
 
 ~ConnectedSocket ()
 Destructor. More...
 
std::string ReadString (const size_t &stringLength, Time timeout)
 
uint16_t ReadUInt16 (Time const &timeout)
 
void WriteUInt16 (uint16_t const &data, Time const &timeout)
 
uint32_t ReadUInt32 (Time const &timeout)
 
void WriteUInt32 (uint32_t const &data, Time const &timeout)
 
- 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 ObjectParent (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 }
 

Detailed Description

Class encapsulating a TCP socket.

Member Function Documentation

void flair::core::TcpSocket::Listen ( const unsigned int  port,
const std::string  localAddress = "ANY" 
)
virtual

Returns a socket which listens on a specific port/address.

Parameters
constObject* parentObject
conststring name
unsignedint port
constlocalAddress (defaults to any)

Implements flair::core::ConnectedSocket.

TcpSocket* flair::core::TcpSocket::Accept ( Time  timeout = 0)
virtual

Returns a socket on a new incoming connexion.

Parameters
ConnectedSocket&listeningSocket

Implements flair::core::ConnectedSocket.

bool flair::core::TcpSocket::Connect ( const unsigned int  port,
const std::string  distantAddress,
Time  timeout = 0 
)
virtual

Returns a socket connected to a distant host.

Parameters
constObject* parentObject
conststring name
unsignedint port
constdistantAddress
timeouttimeout (in milliseconds)

Implements flair::core::ConnectedSocket.

ssize_t flair::core::TcpSocket::SendMessage ( const char *  message,
size_t  message_len,
Time  timeout = 0 
)
virtual

Send a message.

Parameters
messagemessage
message_lenmessage length
timeouttimeout (in milliseconds)

Implements flair::core::ConnectedSocket.

ssize_t flair::core::TcpSocket::RecvMessage ( char *  buf,
size_t  buf_len,
Time  timeout = 0 
)
virtual

Receive a message.

Receive a message and wait up to timeout.

Parameters
bufbuffer to put the message
buf_lenbuffer length
timeouttimeout (in milliseconds)
Returns
size of the received message

Implements flair::core::ConnectedSocket.

uint16_t flair::core::TcpSocket::NetworkToHost16 ( uint16_t  data)
virtual

! See Socket.h for a more generic implementation of network/host endianness

Implements flair::core::ConnectedSocket.