![]() |
ezEngine Release 25.08
|
Public Member Functions | |
| ezMutex & | GetMutex () const |
| Exposes the mutex that is internally used to secure multi-threaded access. | |
Connection | |
| ezResult | StartServer (ezUInt32 uiConnectionToken, ezStringView sAddress, bool bStartUpdateThread=true) |
| Starts the remote interface as a server. | |
| ezResult | ConnectToServer (ezUInt32 uiConnectionToken, ezStringView sAddress, bool bStartUpdateThread=true) |
| Starts the network interface as a client. Tries to connect to the given address. | |
| ezResult | WaitForConnectionToServer (ezTime timeout=ezTime::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. | |
| ezRemoteMode | GetRemoteMode () const |
| Whether the remote interface is inactive, a client or a server. | |
| const ezString & | GetServerAddress () const |
| The address through which the connection was started. | |
| ezUInt32 | GetApplicationID () const |
| Returns the own (random) application ID used to identify this instance. | |
| ezUInt32 | GetConnectionToken () const |
| Returns the connection token used to identify compatible servers/clients. | |
Server Information | |
| const ezString & | GetServerInfoIP () const |
| For the client to display the name of the server. | |
| ezUInt32 | GetServerID () const |
| Some random identifier, that allows to determine after a reconnect, whether the connected instance is still the same server. | |
| ezTime | 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 (ezUInt32 uiSystemID, ezUInt32 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 (ezRemoteTransmitMode tm, ezUInt32 uiSystemID, ezUInt32 uiMsgID, const ezArrayPtr< const ezUInt8 > &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 (ezRemoteTransmitMode tm, ezUInt32 uiSystemID, ezUInt32 uiMsgID, const ezContiguousMemoryStreamStorage &data) |
| void | Send (ezRemoteTransmitMode tm, ezUInt32 uiSystemID, ezUInt32 uiMsgID, const void *pData=nullptr, ezUInt32 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 (ezRemoteTransmitMode tm, ezRemoteMessage &ref_msg) |
| Sends an ezRemoteMessage 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 (ezUInt32 uiSystemID, ezRemoteMessageHandler messageHandler) |
| Registers a message handler that is executed for all incoming messages for the given system. | |
| void | SetUnhandledMessageHandler (ezRemoteMessageHandler messageHandler) |
| Registers a message handler that is executed for all incoming messages for systems for which there are no dedicated message handlers. | |
| ezUInt32 | ExecuteMessageHandlers (ezUInt32 uiSystem) |
| Executes the message handler for all messages that have arrived for the given system. | |
| ezUInt32 | ExecuteAllMessageHandlers () |
| Executes all message handlers for all received messages. | |
Public Attributes | |
Events | |
| ezEvent< const ezRemoteEvent & > | m_RemoteEvents |
| Broadcasts events about connections. | |
Implementation Details | |
| ezString | m_sServerInfoIP |
| Derived classes should update this when the information is available. | |
| virtual ezResult | InternalCreateConnection (ezRemoteMode mode, ezStringView 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 ezTime | InternalGetPingToServer ()=0 |
| Derived classes have to implement this to get the ping to the server (client mode only) | |
| virtual ezResult | InternalTransmit (ezRemoteTransmitMode tm, const ezArrayPtr< const ezUInt8 > &data)=0 |
| Derived classes have to implement this to deliver messages to the server or client. | |
| virtual ezResult | DetermineTargetAddress (ezStringView sConnectTo, ezUInt32 &out_IP, ezUInt16 &out_Port) |
| Derived classes can override this to interpret an address differently. | |
| void | ReportConnectionToServer (ezUInt32 uiServerID) |
| Should be called by the implementation, when a server connection has been established. | |
| void | ReportConnectionToClient (ezUInt32 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 (ezUInt32 uiApplicationID) |
| Should be called by the implementation, when a client connection has been lost. | |
| void | ReportMessage (ezUInt32 uiApplicationID, ezUInt32 uiSystemID, ezUInt32 uiMsgID, const ezArrayPtr< const ezUInt8 > &data) |
| Should be called by the implementation, when a message has arrived. | |
| ezResult ezRemoteInterface::ConnectToServer | ( | ezUInt32 | uiConnectionToken, |
| ezStringView | 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.
| uiConnectionToken | Same as for StartServer() |
| szAddress | Could be a network address "127.0.0.1" or "localhost" or some other name that identifies the target, e.g. a named pipe. |
| bStartUpdateThread | Same as for StartServer() |
If this function succeeds, it still might not be connected to a server. Use WaitForConnectionToServer() to enforce a connection.
|
inline |
For the client to display the name of the server.
For the client to display the IP of the server
| ezResult ezRemoteInterface::StartServer | ( | ezUInt32 | uiConnectionToken, |
| ezStringView | sAddress, | ||
| bool | bStartUpdateThread = true |
||
| ) |
Starts the remote interface as a server.
| uiConnectionToken | Should be a unique sequence (e.g. 'EZPZ') to identify the purpose of this connection. Only server and clients with the same token will accept connections. |
| uiPort | The port over which the connection should run. |
| bStartUpdateThread | If true, a thread is started that will regularly call UpdateNetwork() and UpdatePingToServer(). If false, this has to be called manually in regular intervals. |
| ezResult ezRemoteInterface::WaitForConnectionToServer | ( | ezTime | timeout = ezTime::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.
|
protected |
Derived classes should update this when the information is available.
Derived classes should update this when the information is available