G3D::ReliableConduit Class ReferenceA conduit that guarantees messages will arrive, intact and in order.
More...
#include <NetworkDevice.h>
Inherits G3D::Conduit.
List of all members.
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:
-
Create a G3D::NetworkDevice (if you are using G3D::GApp, it creates one for you) on the client and on the server.
-
On the server, create a G3D::NetListener using G3D::NetworkDevice::createListener
-
On the server, invoke G3D::NetListener::waitForConnection.
-
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 |
( |
|
) |
|
Member Function Documentation
| NetAddress G3D::ReliableConduit::address |
( |
|
) |
const |
| uint64 G3D::Conduit::bytesReceived |
( |
|
) |
const [inherited] |
| uint64 G3D::Conduit::bytesSent |
( |
|
) |
const [inherited] |
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.
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
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:47 2007 for G3D by
1.5.2
Hosted by
|