Connection to a remote network host. More...

#include <Urho3D/Network/Connection.h>

Inheritance diagram for Urho3D::Connection:
[legend]
Collaboration diagram for Urho3D::Connection:
[legend]

Public Member Functions

 Connection (Context *context, bool isClient, kNet::SharedPtr< kNet::MessageConnection > connection)
 Construct with context and kNet message connection pointers. More...
 
 ~Connection ()
 Destruct.
 
void SendMessage (int msgID, bool reliable, bool inOrder, const VectorBuffer &msg, unsigned contentID=0)
 Send a message.
 
void SendMessage (int msgID, bool reliable, bool inOrder, const unsigned char *data, unsigned numBytes, unsigned contentID=0)
 Send a message.
 
void SendRemoteEvent (StringHash eventType, bool inOrder, const VariantMap &eventData=Variant::emptyVariantMap)
 Send a remote event.
 
void SendRemoteEvent (Node *node, StringHash eventType, bool inOrder, const VariantMap &eventData=Variant::emptyVariantMap)
 Send a remote event with the specified node as sender.
 
void SetScene (Scene *newScene)
 Assign scene. On the server, this will cause the client to load it.
 
void SetIdentity (const VariantMap &identity)
 Assign identity. Called by Network.
 
void SetControls (const Controls &newControls)
 Set new controls.
 
void SetPosition (const Vector3 &position)
 Set the observer position for interest management, to be sent to the server.
 
void SetRotation (const Quaternion &rotation)
 Set the observer rotation for interest management, to be sent to the server. Note: not used by the NetworkPriority component.
 
void SetConnectPending (bool connectPending)
 Set the connection pending status. Called by Network.
 
void SetLogStatistics (bool enable)
 Set whether to log data in/out statistics.
 
void Disconnect (int waitMSec=0)
 Disconnect. If wait time is non-zero, will block while waiting for disconnect to finish.
 
void SendServerUpdate ()
 Send scene update messages. Called by Network.
 
void SendClientUpdate ()
 Send latest controls from the client. Called by Network.
 
void SendRemoteEvents ()
 Send queued remote events. Called by Network.
 
void SendPackages ()
 Send package files to client. Called by network.
 
void ProcessPendingLatestData ()
 Process pending latest data for nodes and components.
 
bool ProcessMessage (int msgID, MemoryBuffer &msg)
 Process a message from the server or client. Called by Network.
 
kNet::MessageConnection * GetMessageConnection () const
 Return the kNet message connection.
 
VariantMapGetIdentity ()
 Return client identity.
 
SceneGetScene () const
 Return the scene used by this connection.
 
const ControlsGetControls () const
 Return the client controls of this connection.
 
unsigned char GetTimeStamp () const
 Return the controls timestamp, sent from client to server along each control update.
 
const Vector3GetPosition () const
 Return the observer position sent by the client for interest management.
 
const QuaternionGetRotation () const
 Return the observer rotation sent by the client for interest management.
 
bool IsClient () const
 Return whether is a client connection.
 
bool IsConnected () const
 Return whether is fully connected.
 
bool IsConnectPending () const
 Return whether connection is pending.
 
bool IsSceneLoaded () const
 Return whether the scene is loaded and ready to receive server updates.
 
bool GetLogStatistics () const
 Return whether to log data in/out statistics.
 
String GetAddress () const
 Return remote address.
 
unsigned short GetPort () const
 Return remote port.
 
float GetRoundTripTime () const
 Return the connection's round trip time in milliseconds.
 
float GetLastHeardTime () const
 Return the time since last received data from the remote host in milliseconds.
 
float GetBytesInPerSec () const
 Return bytes received per second.
 
float GetBytesOutPerSec () const
 Return bytes sent per second.
 
float GetPacketsInPerSec () const
 Return packets received per second.
 
float GetPacketsOutPerSec () const
 Return packets sent per second.
 
String ToString () const
 Return an address:port string.
 
unsigned GetNumDownloads () const
 Return number of package downloads remaining.
 
const StringGetDownloadName () const
 Return name of current package download, or empty if no downloads.
 
float GetDownloadProgress () const
 Return progress of current package download, or 1.0 if no downloads.
 
void SendPackageToClient (PackageFile *package)
 Trigger client connection to download a package file from the server. Can be used to download additional resource packages when client is already joined in a scene. The package must have been added as a requirement to the scene the client is joined in, or else the eventual download will fail.
 
void ConfigureNetworkSimulator (int latencyMs, float packetLoss)
 Set network simulation parameters. Called by Network.
 
- Public Member Functions inherited from Urho3D::Object
 Object (Context *context)
 Construct.
 
virtual ~Object ()
 Destruct. Clean up self from event sender & receiver structures.
 
virtual StringHash GetType () const =0
 Return type hash.
 
virtual const StringGetTypeName () const =0
 Return type name.
 
virtual const TypeInfoGetTypeInfo () const =0
 Return type info.
 
virtual void OnEvent (Object *sender, StringHash eventType, VariantMap &eventData)
 Handle event.
 
bool IsInstanceOf (StringHash type) const
 Check current instance is type of specified type.
 
bool IsInstanceOf (const TypeInfo *typeInfo) const
 Check current instance is type of specified type.
 
template<typename T >
bool IsInstanceOf () const
 Check current instance is type of specified class.
 
void SubscribeToEvent (StringHash eventType, EventHandler *handler)
 Subscribe to an event that can be sent by any sender.
 
void SubscribeToEvent (Object *sender, StringHash eventType, EventHandler *handler)
 Subscribe to a specific sender's event.
 
void UnsubscribeFromEvent (StringHash eventType)
 Unsubscribe from an event.
 
void UnsubscribeFromEvent (Object *sender, StringHash eventType)
 Unsubscribe from a specific sender's event.
 
void UnsubscribeFromEvents (Object *sender)
 Unsubscribe from a specific sender's events.
 
void UnsubscribeFromAllEvents ()
 Unsubscribe from all events.
 
void UnsubscribeFromAllEventsExcept (const PODVector< StringHash > &exceptions, bool onlyUserData)
 Unsubscribe from all events except those listed, and optionally only those with userdata (script registered events.)
 
void SendEvent (StringHash eventType)
 Send event to all subscribers.
 
void SendEvent (StringHash eventType, VariantMap &eventData)
 Send event with parameters to all subscribers. More...
 
VariantMapGetEventDataMap () const
 Return a preallocated map for event data. Used for optimization to avoid constant re-allocation of event data maps.
 
ContextGetContext () const
 Return execution context.
 
const VariantGetGlobalVar (StringHash key) const
 Return global variable based on key.
 
const VariantMapGetGlobalVars () const
 Return all global variables.
 
void SetGlobalVar (StringHash key, const Variant &value)
 Set global variable with the respective key and value.
 
ObjectGetSubsystem (StringHash type) const
 Return subsystem by type.
 
ObjectGetEventSender () const
 Return active event sender. Null outside event handling.
 
EventHandlerGetEventHandler () const
 Return active event handler. Null outside event handling.
 
bool HasSubscribedToEvent (StringHash eventType) const
 Return whether has subscribed to an event without specific sender.
 
bool HasSubscribedToEvent (Object *sender, StringHash eventType) const
 Return whether has subscribed to a specific sender's event.
 
bool HasEventHandlers () const
 Return whether has subscribed to any event.
 
template<class T >
T * GetSubsystem () const
 Template version of returning a subsystem.
 
const StringGetCategory () const
 Return object category. Categories are (optionally) registered along with the object factory. Return an empty string if the object category is not registered.
 
- Public Member Functions inherited from Urho3D::RefCounted
 RefCounted ()
 Construct. Allocate the reference count structure and set an initial self weak reference.
 
virtual ~RefCounted ()
 Destruct. Mark as expired and also delete the reference count structure if no outside weak references exist.
 
void AddRef ()
 Increment reference count. Can also be called outside of a SharedPtr for traditional reference counting.
 
void ReleaseRef ()
 Decrement reference count and delete self if no more references. Can also be called outside of a SharedPtr for traditional reference counting.
 
int Refs () const
 Return reference count.
 
int WeakRefs () const
 Return weak reference count.
 
RefCountRefCountPtr ()
 Return pointer to the reference count structure.
 

Public Attributes

Controls controls_
 Current controls.
 
unsigned char timeStamp_
 Controls timestamp. Incremented after each sent update.
 
VariantMap identity_
 Identity map.
 

Private Member Functions

 URHO3D_OBJECT (Connection, Object)
 
void HandleAsyncLoadFinished (StringHash eventType, VariantMap &eventData)
 Handle scene loaded event.
 
void ProcessLoadScene (int msgID, MemoryBuffer &msg)
 Process a LoadScene message from the server. Called by Network.
 
void ProcessSceneChecksumError (int msgID, MemoryBuffer &msg)
 Process a SceneChecksumError message from the server. Called by Network.
 
void ProcessSceneUpdate (int msgID, MemoryBuffer &msg)
 Process a scene update message from the server. Called by Network. More...
 
void ProcessPackageDownload (int msgID, MemoryBuffer &msg)
 Process package download related messages. Called by Network.
 
void ProcessIdentity (int msgID, MemoryBuffer &msg)
 Process an Identity message from the client. Called by Network.
 
void ProcessControls (int msgID, MemoryBuffer &msg)
 Process a Controls message from the client. Called by Network.
 
void ProcessSceneLoaded (int msgID, MemoryBuffer &msg)
 Process a SceneLoaded message from the client. Called by Network.
 
void ProcessRemoteEvent (int msgID, MemoryBuffer &msg)
 Process a remote event message from the client or server. Called by Network.
 
void ProcessNode (unsigned nodeID)
 Process a node for sending a network update. Recurses to process depended on node(s) first.
 
void ProcessNewNode (Node *node)
 Process a node that the client has not yet received.
 
void ProcessExistingNode (Node *node, NodeReplicationState &nodeState)
 Process a node that the client has already received. More...
 
void ProcessPackageInfo (int msgID, MemoryBuffer &msg)
 Process a SyncPackagesInfo message from server.
 
bool RequestNeededPackages (unsigned numPackages, MemoryBuffer &msg)
 Check a package list received from server and initiate package downloads as necessary. Return true on success, or false if failed to initialze downloads (cache dir not set)
 
void RequestPackage (const String &name, unsigned fileSize, unsigned checksum)
 Initiate a package download.
 
void SendPackageError (const String &name)
 Send an error reply for a package download.
 
void OnSceneLoadFailed ()
 Handle scene load failure on the server or client.
 
void OnPackageDownloadFailed (const String &name)
 Handle a package download failure on the client.
 
void OnPackagesReady ()
 Handle all packages loaded successfully. Also called directly on MSG_LOADSCENE if there are none.
 

Private Attributes

kNet::SharedPtr
< kNet::MessageConnection > 
connection_
 kNet message connection.
 
WeakPtr< Scenescene_
 Scene.
 
SceneReplicationState sceneState_
 Network replication state of the scene.
 
HashMap< StringHash,
PackageDownload
downloads_
 Waiting or ongoing package file receive transfers.
 
HashMap< StringHash,
PackageUpload
uploads_
 Ongoing package send transfers.
 
HashMap< unsigned, PODVector
< unsigned char > > 
nodeLatestData_
 Pending latest data for not yet received nodes.
 
HashMap< unsigned, PODVector
< unsigned char > > 
componentLatestData_
 Pending latest data for not yet received components.
 
HashSet< unsigned > nodesToProcess_
 Node ID's to process during a replication update.
 
VectorBuffer msg_
 Reusable message buffer.
 
Vector< RemoteEventremoteEvents_
 Queued remote events.
 
String sceneFileName_
 Scene file to load once all packages (if any) have been downloaded.
 
Timer statsTimer_
 Statistics timer.
 
String address_
 Remote endpoint address.
 
unsigned short port_
 Remote endpoint port.
 
Vector3 position_
 Observer position for interest management.
 
Quaternion rotation_
 Observer rotation for interest management.
 
ObserverPositionSendMode sendMode_
 Send mode for the observer position & rotation.
 
bool isClient_
 Client connection flag.
 
bool connectPending_
 Connection pending flag.
 
bool sceneLoaded_
 Scene loaded flag.
 
bool logStatistics_
 Show statistics flag.
 

Additional Inherited Members

- Static Public Member Functions inherited from Urho3D::Object
static const TypeInfoGetTypeInfoStatic ()
 Return type info static.
 
static bool IsTypeOf (StringHash type)
 Check current type is type of specified type.
 
static bool IsTypeOf (const TypeInfo *typeInfo)
 Check current type is type of specified type.
 
template<typename T >
static bool IsTypeOf ()
 Check current type is type of specified class.
 
- Protected Attributes inherited from Urho3D::Object
Contextcontext_
 Execution context.
 

Detailed Description

Connection to a remote network host.

Constructor & Destructor Documentation

Urho3D::Connection::Connection ( Context context,
bool  isClient,
kNet::SharedPtr< kNet::MessageConnection >  connection 
)

Construct with context and kNet message connection pointers.

Todo:
Not IPv6-capable.

Member Function Documentation

void Urho3D::Connection::ProcessExistingNode ( Node node,
NodeReplicationState nodeState 
)
private

Process a node that the client has already received.

Todo:
Searching for the component is a potential CPU hotspot. It should be cached

Here is the caller graph for this function:

void Urho3D::Connection::ProcessSceneUpdate ( int  msgID,
MemoryBuffer msg 
)
private

Process a scene update message from the server. Called by Network.

Todo:
On mobile devices processing this message may potentially cause a crash if it attempts to load new GPU resources while the application is minimized

Here is the call graph for this function:

Here is the caller graph for this function:


The documentation for this class was generated from the following files:
  • Source/Urho3D/Network/Connection.h
  • Source/Urho3D/Network/Connection.cpp