G3D::LightweightConduit Class Reference#include <NetworkDevice.h>
Inherits G3D::Conduit.
List of all members.
|
Public Member Functions |
| | ~LightweightConduit () |
| int | maxMessageSize () const |
| void | send (const NetAddress &a, const NetMessage *m) |
| template<typename T> |
| void | send (const NetAddress &a, uint32 type, const T &msg) |
| void | send (const Array< NetAddress > &a, const NetMessage *m) |
| template<typename T> |
| void | send (const Array< NetAddress > &a, uint32 type, const T &m) |
| void | send (const Array< NetAddress > &a, const NetMessage &m) |
| void | send (const Array< NetAddress > &a) |
| void | send (const NetAddress &a, const NetMessage &m) |
| void | send (const NetAddress &a) |
| bool | receive (NetAddress &sender, NetMessage *m) |
| template<typename T> |
| bool | receive (NetAddress &sender, T &message) |
| bool | receive (NetAddress &sender, NetMessage &m) |
| bool | receive (NetAddress &sender) |
| bool | receive () |
| virtual uint32 | waitingMessageType () |
| virtual bool | messageWaiting () const |
| uint64 | bytesSent () const |
| uint64 | messagesSent () const |
| uint64 | bytesReceived () const |
| uint64 | messagesReceived () const |
| bool | ok () const |
| void | ReferenceCountedObject_zeroWeakPointers () |
Public Attributes |
| AtomicInt32 | ReferenceCountedObject_refCount |
| _WeakPtrLinkedList * | ReferenceCountedObject_weakPointer |
Protected Attributes |
| uint64 | mSent |
| uint64 | mReceived |
| uint64 | bSent |
| uint64 | bReceived |
| NetworkDevice * | nd |
| SOCKET | sock |
| BinaryOutput | binaryOutput |
Friends |
| class | NetworkDevice |
| class | NetListener |
Classes |
| class | PacketSizeException |
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]
-
Create a G3D::NetworkDevice on program startup (if you use G3D::GApp, it will do this for you)
-
Call G3D::NetworkDevice::createLightweightConduit(port, true, false), where port is the port on which you will receive messages.
-
Poll G3D::LightWeightcontuit::messageWaiting from your main loop. When it is true (or, equivalently, when G3D::LightWeightcontuit::waitingMessageType is non-zero) there is an incoming message.
-
To read the incoming message, call G3D::LightWeightconduit::receive with the appropriate subclass of G3D::NetMessage. G3D::LightWeightcontuit::waitingMessageType tells you what subclass 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]
-
Create a G3D::NetworkDevice on program startup (if you use G3D::GApp, it will do this for you)
-
Call G3D::NetworkDevice::createLightweightConduit(). 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 |
( |
|
) |
const [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] |
|
| bool G3D::LightweightConduit::receive |
( |
NetAddress & |
sender |
) |
[inline] |
|
|
template<typename T> |
| bool G3D::LightweightConduit::receive |
( |
NetAddress & |
sender, |
|
|
T & |
message |
|
) |
[inline] |
|
|
|
If data is waiting, deserializes the waiting message into m, puts the sender's address in addr and returns true, otherwise returns false. If m is NULL, the message is consumed but not deserialized. |
| 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::LightweightConduit::send |
( |
const NetAddress & |
a |
) |
[inline] |
|
| void G3D::LightweightConduit::send |
( |
const Array< NetAddress > & |
a |
) |
[inline] |
|
|
template<typename T> |
| void G3D::LightweightConduit::send |
( |
const Array< NetAddress > & |
a, |
|
|
uint32 |
type, |
|
|
const T & |
m |
|
) |
[inline] |
|
|
|
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) |
|
|
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) - Deprecated:
|
|
template<typename T> |
| void G3D::LightweightConduit::send |
( |
const NetAddress & |
a, |
|
|
uint32 |
type, |
|
|
const T & |
msg |
|
) |
[inline] |
|
|
|
Serializes and sends the message immediately. Data may not arrive and may arrive out of order, but individual messages are guaranteed to not be corrupted. If the message is null, an empty message is still sent.
Throws PacketSizeException if the serialized message exceeds maxMessageSize. |
| 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 Mon Jul 17 11:50:46 2006 for G3D by
1.4.5
Hosted by
|