Contents User Forum Source Index APIs by Task APIs by Level Data


G3D::ReliableConduit Class Reference

A conduit that guarantees messages will arrive, intact and in order. More...

#include <NetworkDevice.h>

Inherits G3D::Conduit.

List of all members.

Public Member Functions

NetAddress address () const
uint64 bytesReceived () const
uint64 bytesSent () const
uint64 messagesReceived () const
uint64 messagesSent () const
virtual bool messageWaiting ()
bool ok () const
void receive ()
template<typename T>
bool receive (T &message)
void ReferenceCountedObject_zeroWeakPointers ()
void send (uint32 type)
template<typename T>
void send (uint32 type, const T &message)
virtual uint32 waitingMessageType ()
 ~ReliableConduit ()

Static Public Member Functions

static ReliableConduitRef create (const NetAddress &address)
template<typename T>
static void multisend (const Array< ReliableConduitRef > &array, uint32 type, const T &m)

Public Attributes

AtomicInt32 ReferenceCountedObject_refCount
_WeakPtrLinkedListReferenceCountedObject_weakPointer

Protected Attributes

BinaryOutput binaryOutput
uint64 bReceived
uint64 bSent
uint64 mReceived
uint64 mSent
SOCKET sock

Friends

class NetListener
class NetworkDevice


Detailed Description

A conduit that guarantees messages will arrive, intact and in order.

Create on the client using NetworkDevice::createReliableConduit and on the server using NetListener::waitForConnection. Set the reference counted pointer to NULL to disconnect.

To construct a ReliableConduit:

  1. Create a G3D::NetworkDevice (if you are using G3D::GApp, it creates one for you) on the client and on the server.
  2. On the server, create a G3D::NetListener using G3D::NetworkDevice::createListener
  3. On the server, invoke G3D::NetListener::waitForConnection.
  4. On the client, call G3D::NetworkDevice::createReliableConduit. You will need the server's G3D::NetAddress. Consider using G3D::DiscoveryClient to find it via broadcasting.


Constructor & Destructor Documentation

G3D::ReliableConduit::~ReliableConduit (  ) 

Closes the socket.


Member Function Documentation

NetAddress G3D::ReliableConduit::address (  )  const

uint64 G3D::Conduit::bytesReceived (  )  const [inherited]

uint64 G3D::Conduit::bytesSent (  )  const [inherited]

static ReliableConduitRef G3D::ReliableConduit::create ( const NetAddress address  )  [static]

Client invokes this to connect to a server.

The call blocks until the conduit is opened. The conduit will not be ok() if it fails.

uint64 G3D::Conduit::messagesReceived (  )  const [inherited]

uint64 G3D::Conduit::messagesSent (  )  const [inherited]

virtual bool G3D::ReliableConduit::messageWaiting (  )  [virtual]

If true, receive will return true.

Reimplemented from G3D::Conduit.

template<typename T>
static void G3D::ReliableConduit::multisend ( const Array< ReliableConduitRef > &  array,
uint32  type,
const T &  m 
) [inline, static]

Send the same message to a number of conduits.

Useful for sending data from a server to many clients (only serializes once).

bool G3D::Conduit::ok (  )  const [inherited]

Returns true if the connection is ok.

void G3D::ReliableConduit::receive (  )  [inline]

Removes the current message from the queue.

template<typename T>
bool G3D::ReliableConduit::receive ( T &  message  )  [inline]

If a message is waiting, deserializes the waiting message into message and returns true, otherwise returns false.

You can determine the type of the message (and therefore, the class of message) using G3D::ReliableConduit::waitingMessageType().

void G3D::ReferenceCountedObject::ReferenceCountedObject_zeroWeakPointers (  )  [inline, inherited]

Automatically called immediately before the object is deleted.

This is not called from the destructor because it needs to be invoked before the subclass destructor.

void G3D::ReliableConduit::send ( uint32  type  ) 

Sends an empty message with the given type.

Useful for sending commands that have no parameters.

template<typename T>
void G3D::ReliableConduit::send ( uint32  type,
const T &  message 
) [inline]

Serializes the message and schedules it to be sent as soon as possible, and then returns immediately.

The message can be any class with a serialize and deserialize method. On the receiving side, use G3D::ReliableConduit::waitingMessageType() to detect the incoming message and then invoke G3D::ReliableConduit::receive(msg) where msg is of the same class as the message that was sent.

The actual data sent across the network is preceeded by the message type and the size of the serialized message as a 32-bit integer. The size is sent because TCP is a stream protocol and doesn't have a concept of discrete messages.

virtual uint32 G3D::ReliableConduit::waitingMessageType (  )  [virtual]

Returns the type of the waiting message (i.e.

the type supplied with send). The return value is zero when there is no message waiting.

One way to use this is to have a Table mapping message types to pre-allocated NetMessage subclasses so receiving looks like:

My base class for messages.
         class Message : public NetMessage {
             virtual void process() = 0;
         };

         Message* m = table[conduit->waitingMessageType()];
         conduit->receive(m);
         m->process();
     

Another is to simply SWITCH on the message type.

Implements G3D::Conduit.


Friends And Related Function Documentation

friend class NetListener [friend]

Reimplemented from G3D::Conduit.

friend class NetworkDevice [friend]

Reimplemented from G3D::Conduit.


Member Data Documentation

BinaryOutput G3D::Conduit::binaryOutput [protected, inherited]

Used for serialization.

One per socket to make this threadsafe.

uint64 G3D::Conduit::bReceived [protected, inherited]

uint64 G3D::Conduit::bSent [protected, inherited]

uint64 G3D::Conduit::mReceived [protected, inherited]

uint64 G3D::Conduit::mSent [protected, inherited]

The long name is to keep this from accidentally conflicting with a subclass's variable name.

Do not use or explicitly manipulate this value--its type may change in the future and is not part of the supported API.

Linked list of all weak pointers that reference this (some may be on the stack!).

Do not use or explicitly manipulate this value.

SOCKET G3D::Conduit::sock [protected, inherited]


The documentation for this class was generated from the following file:
Generated on Thu Aug 2 11:40:47 2007 for G3D by doxygen 1.5.2
Hosted by SourceForge.net Logo