Plasma Engine  2.0
Loading...
Searching...
No Matches
plRemoteInterface Class Referenceabstract

Public Member Functions

plMutexGetMutex () const
 Exposes the mutex that is internally used to secure multi-threaded access.
 
Connection
plResult StartServer (plUInt32 uiConnectionToken, plStringView sAddress, bool bStartUpdateThread=true)
 Starts the remote interface as a server.
 
plResult ConnectToServer (plUInt32 uiConnectionToken, plStringView sAddress, bool bStartUpdateThread=true)
 Starts the network interface as a client. Tries to connect to the given address.
 
plResult WaitForConnectionToServer (plTime timeout=plTime::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.
 
plRemoteMode GetRemoteMode () const
 Whether the remote interface is inactive, a client or a server.
 
const plStringGetServerAddress () const
 The address through which the connection was started.
 
plUInt32 GetApplicationID () const
 Returns the own (random) application ID used to identify this instance.
 
plUInt32 GetConnectionToken () const
 Returns the connection token used to identify compatible servers/clients.
 
Server Information
const plStringGetServerInfoIP () const
 For the client to display the name of the server.
 
plUInt32 GetServerID () const
 Some random identifier, that allows to determine after a reconnect, whether the connected instance is still the same server.
 
plTime 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 (plUInt32 uiSystemID, plUInt32 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 (plRemoteTransmitMode tm, plUInt32 uiSystemID, plUInt32 uiMsgID, const plArrayPtr< const plUInt8 > &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 (plRemoteTransmitMode tm, plUInt32 uiSystemID, plUInt32 uiMsgID, const plContiguousMemoryStreamStorage &data)
 
void Send (plRemoteTransmitMode tm, plUInt32 uiSystemID, plUInt32 uiMsgID, const void *pData=nullptr, plUInt32 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 (plRemoteTransmitMode tm, plRemoteMessage &ref_msg)
 Sends an plRemoteMessage 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 (plUInt32 uiSystemID, plRemoteMessageHandler messageHandler)
 Registers a message handler that is executed for all incoming messages for the given system.
 
void SetUnhandledMessageHandler (plRemoteMessageHandler messageHandler)
 Registers a message handler that is executed for all incoming messages for systems for which there are no dedicated message handlers.
 
plUInt32 ExecuteMessageHandlers (plUInt32 uiSystem)
 Executes the message handler for all messages that have arrived for the given system.
 
plUInt32 ExecuteAllMessageHandlers ()
 Executes all message handlers for all received messages.
 

Public Attributes

Events
plEvent< const plRemoteEvent & > m_RemoteEvents
 Broadcasts events about connections.
 

Implementation Details

plString m_sServerInfoIP
 Derived classes should update this when the information is available.
 
virtual plResult InternalCreateConnection (plRemoteMode mode, plStringView 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 plTime InternalGetPingToServer ()=0
 Derived classes have to implement this to get the ping to the server (client mode only)
 
virtual plResult InternalTransmit (plRemoteTransmitMode tm, const plArrayPtr< const plUInt8 > &data)=0
 Derived classes have to implement this to deliver messages to the server or client.
 
virtual plResult DetermineTargetAddress (plStringView sConnectTo, plUInt32 &out_IP, plUInt16 &out_Port)
 Derived classes can override this to interpret an address differently.
 
void ReportConnectionToServer (plUInt32 uiServerID)
 Should be called by the implementation, when a server connection has been established.
 
void ReportConnectionToClient (plUInt32 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 (plUInt32 uiApplicationID)
 Should be called by the implementation, when a client connection has been lost.
 
void ReportMessage (plUInt32 uiApplicationID, plUInt32 uiSystemID, plUInt32 uiMsgID, const plArrayPtr< const plUInt8 > &data)
 Should be called by the implementation, when a message has arrived.
 

Member Function Documentation

◆ ConnectToServer()

plResult plRemoteInterface::ConnectToServer ( plUInt32 uiConnectionToken,
plStringView 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 plString & plRemoteInterface::GetServerInfoIP ( ) const
inline

For the client to display the name of the server.

For the client to display the IP of the server

◆ StartServer()

plResult plRemoteInterface::StartServer ( plUInt32 uiConnectionToken,
plStringView sAddress,
bool bStartUpdateThread = true )

Starts the remote interface as a server.

Parameters
uiConnectionTokenShould be a unique sequence (e.g. 'PLPZ') 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()

plResult plRemoteInterface::WaitForConnectionToServer ( plTime timeout = plTime::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

plString plRemoteInterface::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: