XII Release 0.1.0
Loading...
Searching...
No Matches
xiiRemoteInterface Class Referenceabstract

Public Member Functions

xiiMutexGetMutex () const
 Exposes the mutex that is internally used to secure multi-threaded access.
 
Connection
xiiResult StartServer (xiiUInt32 uiConnectionToken, xiiStringView sAddress, bool bStartUpdateThread=true)
 Starts the remote interface as a server.
 
xiiResult ConnectToServer (xiiUInt32 uiConnectionToken, xiiStringView sAddress, bool bStartUpdateThread=true)
 Starts the network interface as a client. Tries to connect to the given address.
 
xiiResult WaitForConnectionToServer (xiiTime timeout=xiiTime::MakeFromSeconds(10))
 Can only be called after ConnectToServer(). Updates the network in a loop until a connection is established, or the time has run out.
 
void ShutdownConnection ()
 Closes the connection in an orderly fashion.
 
bool IsConnectedToServer () const
 Whether the client is connected to a server.
 
bool IsConnectedToClients () const
 Whether the server is connected to any client.
 
bool IsConnectedToOther () const
 Whether the client or server is connected its counterpart.
 
xiiRemoteMode GetRemoteMode () const
 Whether the remote interface is inactive, a client or a server.
 
const xiiStringGetServerAddress () const
 The address through which the connection was started.
 
xiiUInt32 GetApplicationID () const
 Returns the own (random) application ID used to identify this instance.
 
xiiUInt32 GetConnectionToken () const
 Returns the connection token used to identify compatible servers/clients.
 
Server Information
const xiiStringGetServerInfoIP () const
 For the client to display the name of the server.
 
xiiUInt32 GetServerID () const
 Some random identifier, that allows to determine after a reconnect, whether the connected instance is still the same server.
 
xiiTime GetPingToServer () const
 Returns the current ping to the server.
 
Updating the Remote Interface
void UpdateRemoteInterface ()
 If no update thread was spawned, this should be called to process messages.
 
void UpdatePingToServer ()
 If no update thread was spawned, this should be called by clients to determine the ping.
 
Sending Messages
void Send (xiiUInt32 uiSystemID, xiiUInt32 uiMsgID)
 Sends a reliable message without any data. If it is a server, the message is broadcast to all clients. If it is a client, the message is only sent to the server.
 
void Send (xiiRemoteTransmitMode tm, xiiUInt32 uiSystemID, xiiUInt32 uiMsgID, const xiiArrayPtr< const xiiUInt8 > &data)
 Sends a message, appends the given array of data If it is a server, the message is broadcast to all clients. If it is a client, the message is only sent to the server.
 
void Send (xiiRemoteTransmitMode tm, xiiUInt32 uiSystemID, xiiUInt32 uiMsgID, const xiiContiguousMemoryStreamStorage &data)
 
void Send (xiiRemoteTransmitMode tm, xiiUInt32 uiSystemID, xiiUInt32 uiMsgID, const void *pData=nullptr, xiiUInt32 uiDataBytes=0)
 Sends a message, appends the given array of data If it is a server, the message is broadcast to all clients. If it is a client, the message is only sent to the server.
 
void Send (xiiRemoteTransmitMode tm, xiiRemoteMessage &ref_msg)
 Sends a xiiRemoteMessage If it is a server, the message is broadcast to all clients. If it is a client, the message is only sent to the server.
 
Message Handling
void SetMessageHandler (xiiUInt32 uiSystemID, xiiRemoteMessageHandler messageHandler)
 Registers a message handler that is executed for all incoming messages for the given system.
 
void SetUnhandledMessageHandler (xiiRemoteMessageHandler messageHandler)
 Registers a message handler that is executed for all incoming messages for systems for which there are no dedicated message handlers.
 
xiiUInt32 ExecuteMessageHandlers (xiiUInt32 uiSystem)
 Executes the message handler for all messages that have arrived for the given system.
 
xiiUInt32 ExecuteAllMessageHandlers ()
 Executes all message handlers for all received messages.
 

Public Attributes

Events
xiiEvent< const xiiRemoteEvent & > m_RemoteEvents
 Broadcasts events about connections.
 

Implementation Details

xiiString m_sServerInfoIP
 Derived classes should update this when the information is available.
 
virtual xiiResult InternalCreateConnection (xiiRemoteMode mode, xiiStringView sServerAddress)=0
 Derived classes have to implement this to start a network connection.
 
virtual void InternalShutdownConnection ()=0
 Derived classes have to implement this to shutdown a network connection.
 
virtual void InternalUpdateRemoteInterface ()=0
 Derived classes have to implement this to update.
 
virtual xiiTime InternalGetPingToServer ()=0
 Derived classes have to implement this to get the ping to the server (client mode only)
 
virtual xiiResult InternalTransmit (xiiRemoteTransmitMode tm, const xiiArrayPtr< const xiiUInt8 > &data)=0
 Derived classes have to implement this to deliver messages to the server or client.
 
virtual xiiResult DetermineTargetAddress (xiiStringView sConnectTo, xiiUInt32 &out_IP, xiiUInt16 &out_Port)
 Derived classes can override this to interpret an address differently.
 
void ReportConnectionToServer (xiiUInt32 uiServerID)
 Should be called by the implementation, when a server connection has been established.
 
void ReportConnectionToClient (xiiUInt32 uiApplicationID)
 Should be called by the implementation, when a client connection has been established.
 
void ReportDisconnectedFromServer ()
 Should be called by the implementation, when a server connection has been lost.
 
void ReportDisconnectedFromClient (xiiUInt32 uiApplicationID)
 Should be called by the implementation, when a client connection has been lost.
 
void ReportMessage (xiiUInt32 uiApplicationID, xiiUInt32 uiSystemID, xiiUInt32 uiMsgID, const xiiArrayPtr< const xiiUInt8 > &data)
 Should be called by the implementation, when a message has arrived.
 

Member Function Documentation

◆ ConnectToServer()

xiiResult xiiRemoteInterface::ConnectToServer ( xiiUInt32 uiConnectionToken,
xiiStringView sAddress,
bool bStartUpdateThread = true )

Starts the network interface as a client. Tries to connect to the given address.

This function immediately returns and no connection is guaranteed.

Parameters
uiConnectionTokenSame as for StartServer()
szAddressCould be a network address "127.0.0.1" or "localhost" or some other name that identifies the target, e.g. a named pipe.
bStartUpdateThreadSame as for StartServer()

If this function succeeds, it still might not be connected to a server. Use WaitForConnectionToServer() to enforce a connection.

◆ GetServerInfoIP()

const xiiString & xiiRemoteInterface::GetServerInfoIP ( ) const
inline

For the client to display the name of the server.

For the client to display the IP of the server

◆ StartServer()

xiiResult xiiRemoteInterface::StartServer ( xiiUInt32 uiConnectionToken,
xiiStringView sAddress,
bool bStartUpdateThread = true )

Starts the remote interface as a server.

Parameters
uiConnectionTokenShould be a unique sequence (e.g. 'XIIPZ') to identify the purpose of this connection. Only server and clients with the same token will accept connections.
uiPortThe port over which the connection should run.
bStartUpdateThreadIf true, a thread is started that will regularly call UpdateNetwork() and UpdatePingToServer(). If false, this has to be called manually in regular intervals.

◆ WaitForConnectionToServer()

xiiResult xiiRemoteInterface::WaitForConnectionToServer ( xiiTime timeout = xiiTime::MakeFromSeconds(10))

Can only be called after ConnectToServer(). Updates the network in a loop until a connection is established, or the time has run out.

A timeout of exactly zero means to wait indefinitely.

Member Data Documentation

◆ m_sServerInfoIP

xiiString xiiRemoteInterface::m_sServerInfoIP
protected

Derived classes should update this when the information is available.

Derived classes should update this when the information is available


The documentation for this class was generated from the following files: