Yagl::BiDirectionalConnection Class Reference

#include <bidirectionalconnection.h>

Inheritance diagram for Yagl::BiDirectionalConnection:

Yagl::Thread List of all members.

Public Member Functions

 BiDirectionalConnection ()
 Constructor.
virtual ~BiDirectionalConnection ()
 Destructor.
bool isAlive ()
 returns true or false depending on wheter the connection is still alive
void setSocket (int socket)
 sets the socket descriptor
void setLocalPort (unsigned short port)
 sets the local port
void setRemoteAddress (std::string address)
 sets the remote address
void setRemoteAddress (std::string &address)
 sets the remote address
void setRemotePort (unsigned short port)
 sets the remote port
bool connect (const char *address, unsigned short port)
 connects to the given destination
void registerMessageReceiver (MessageReceiver *receiver)
 registers a message receiver
void unregisterMessageReceiver (MessageReceiver *receiver)
 unregisters a message receiver
void disconnect ()
 disconnects
bool send (Message &message)
 sends the given message
void receive ()
 the threaded receive loop
void * run ()
 for internal usage only ( threading )

Protected Member Functions

 BiDirectionalConnection (const BiDirectionalConnection &connection)

Protected Attributes

int socket_
 socket descriptor

Detailed Description

SockBiDirectionalConnection this is a full implementation of the BiDirectionalConnection abstract interface. it is a backend based on berkley/win sockets. the class provides methods to connect to other machines and send and receive messages from to and from other machines. the receive method is asynchronous and runs in it's own thread. one has to register MessageReceivers that will get feed with new incoming Messages in order to obtain those messages in the main programm. This kind of connections should be created and destroyed via the SockNETInterface


Constructor & Destructor Documentation

Yagl::BiDirectionalConnection::BiDirectionalConnection const BiDirectionalConnection connection  )  [protected]
 

copy constructor hidden

Yagl::BiDirectionalConnection::BiDirectionalConnection  )  [inline]
 

Constructor.

sets up internal members

virtual Yagl::BiDirectionalConnection::~BiDirectionalConnection  )  [inline, virtual]
 

Destructor.

disconnects if the conection is still open and stops the receiving thread


Member Function Documentation

bool Yagl::BiDirectionalConnection::connect const char *  address,
unsigned short  port
 

connects to the given destination

this method will try to connect to the given address and port. if the connection attempt is successfully the receiving thread is started and true is returned. if the connection attempt was not successfull false is returned

Parameters:
address the address of the remote machine
port the port of the remote machine

void Yagl::BiDirectionalConnection::disconnect  ) 
 

disconnects

this disconnects a connection. then receiving thread will be exited if running.

void Yagl::BiDirectionalConnection::receive  ) 
 

the threaded receive loop

this is the threaded receive loop that will wait for incoming messages and pass them to the message receiver. messages will only be passed to the receivers when they are fully reassembled ( as they can get fragmented over the network ) the thread will start receiving as soon as there is at least one message receiver registered.

void Yagl::BiDirectionalConnection::registerMessageReceiver MessageReceiver receiver  ) 
 

registers a message receiver

this method should be called before connecting to a remote host. it will register a message receiver that will receive any incoming messages. one can register as many receivers as he/she wants. in case of an accepted incoming connection returned by ListeningConnection one can register a new receiver too. the receive thread will wait until the first receiver is registered and only then start to actually receive data.

bool Yagl::BiDirectionalConnection::send Message message  ) 
 

sends the given message

this will send the given message if the connection is open. the message size is irrelevant in that case as it will be split up into 2kb packages that have a good throughput ratio. it is no problem to send multiple megabyte big message in one go.

Parameters:
message the message to send
Returns:
true or false depending wheter the send was successfull or not.

void Yagl::BiDirectionalConnection::setLocalPort unsigned short  port  ) 
 

sets the local port

this method sets the local port this connection should work on. call this function prior to connect if you want the connection to work on a certain port. if the connection is already running (e.g. it was returned from a ListeningConnection) a call to this method has no effect

void Yagl::BiDirectionalConnection::setRemoteAddress std::string &  address  ) 
 

sets the remote address

for internal usage

void Yagl::BiDirectionalConnection::setRemoteAddress std::string  address  ) 
 

sets the remote address

for internal usage

void Yagl::BiDirectionalConnection::setRemotePort unsigned short  port  ) 
 

sets the remote port

for internal usage

void Yagl::BiDirectionalConnection::setSocket int  socket  ) 
 

sets the socket descriptor

for internal usage only

void Yagl::BiDirectionalConnection::unregisterMessageReceiver MessageReceiver receiver  ) 
 

unregisters a message receiver

this will unregister a message receiver.


The documentation for this class was generated from the following file:
Generated on Tue Jan 10 15:42:38 2006 for YAGL - yet another gameprogramming library by  doxygen 1.4.5