G3D::LightweightConduit Class ReferenceProvides fast but unreliable transfer of messages.
More...
#include <NetworkDevice.h>
Inherits G3D::Conduit.
List of all members.
Detailed Description
Provides fast but unreliable transfer of messages.
On a LAN, LightweightConduit will probably never drop messages but you might get your messages out of order. On an internet connection it might drop messages altogether. Messages are never corrupted, however. LightweightConduit requires a little less setup and overhead than ReliableConduit. ReliableConduit guarantees message delivery and order but requires a persistent connection.
To set up a LightweightConduit (assuming you have already made subclasses of G3D::NetMessage based on your application's pcommunication protocol):
[Server Side]
-
Call LightweightConduit::create(port, true, false), where port is the port on which you will receive messages.
-
Poll LightweightConduit::messageWaiting from your main loop. When it is true (or, equivalently, when LightweightConduit::waitingMessageType is non-zero) there is an incoming message.
-
To read the incoming message, call LightweightConduit::receive with the appropriate class type, which mist have a deserialize method. LightweightConduit::waitingMessageType tells you what class is needed (you make up your own message constants for your program; numbers under 1000 are reserved for G3D's internal use).
-
When done, simply set the G3D::LightweightConduitRef to NULL or let it go out of scope and the conduit cleans itself up automatically.
[Client Side]
-
Call G3D::LightweightConduit::create(). If you will broadcast to all servers on a LAN, set the third optional argument to true (the default is false for no broadcast). You can also set up the receive port as if it was a server to send and receive from a single LightweightConduit.
-
To send, call G3D::LightweightConduit::send with the target address and a pointer to an instance of the message you want to send.
-
When done, simply set the G3D::LightweightConduitRef to NULL or let it go out of scope and the conduit cleans itself up automatically.
Constructor & Destructor Documentation
| G3D::LightweightConduit::~LightweightConduit |
( |
|
) |
|
Member Function Documentation
| uint64 G3D::Conduit::bytesReceived |
( |
|
) |
const [inherited] |
| uint64 G3D::Conduit::bytesSent |
( |
|
) |
const [inherited] |
| int G3D::LightweightConduit::maxMessageSize |
( |
|
) |
const [inline] |
The maximum length of a message that can be sent (G3D places a small header at the front of each UDP packet; this is already taken into account by the value returned).
| uint64 G3D::Conduit::messagesReceived |
( |
|
) |
const [inherited] |
| uint64 G3D::Conduit::messagesSent |
( |
|
) |
const [inherited] |
| virtual bool G3D::LightweightConduit::messageWaiting |
( |
|
) |
[virtual] |
If true, receive will return true.
Reimplemented from G3D::Conduit.
| bool G3D::Conduit::ok |
( |
|
) |
const [inherited] |
Returns true if the connection is ok.
| bool G3D::LightweightConduit::receive |
( |
|
) |
[inline] |
template<typename T>
| bool G3D::LightweightConduit::receive |
( |
NetAddress & |
sender, |
|
|
T & |
message | |
|
) |
| | [inline] |
| bool G3D::LightweightConduit::receive |
( |
NetAddress & |
sender |
) |
|
| 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.
Send the same message to multiple addresses (only serializes once).
Useful when server needs to send to a known list of addresses (unlike direct UDP broadcast to all addresses on the subnet)
template<typename T>
| void G3D::LightweightConduit::send |
( |
const NetAddress & |
a, |
|
|
uint32 |
type, |
|
|
const T & |
msg | |
|
) |
| | [inline] |
| virtual uint32 G3D::LightweightConduit::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
Member Data Documentation
Used for serialization.
One per socket to make this threadsafe.
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.
The documentation for this class was generated from the following file:
Generated on Thu Aug 2 11:40:46 2007 for G3D by
1.5.2
Hosted by
|