Diarkis Inc.

Top > Blog > RPC – Remote Procedure Call With Diarkis

RPC – Remote Procedure Call With Diarkis

This article is based on the older version. The latest article on RPC is here.

Diarkis enables you to implement client-to-client (s) RPC. In this article, we will explain how to implement RPC using Diarkis’ Room module.

The room module can act as an RPC message broker. You may execute RPC operations between room member clients.

How To Invoke RCP On A Remote Client

By sending an RPC message to a remote client in the same room, you may execute an RPC command on the remote client.

NOTE: msgData shown here is an example and it is not included in the client SDK.

RPC Sender Code Example:

msgData.Type = MSG_TYPE_RPC; // This tells the receiver it is an RPC
msgData.ID = 100; // This is the RPC ID to be executed
msgData.Parameters = parameterList;
List<string> remoteClis = new List<string>();
remoteClis.Add(otherMemberUserID);
bool reliable = true;
// Send the RPC to one remote client in a room
room.MessageTo(room.GetRoomID(), remoteClis, msgData.Encode(), reliable);

How To Invoke RPC On Multiple Clients

You may send an RPC command to multiple remote clients in the same room.

NOTE: msgData shown here is an example and it is not included in the client SDK.

RPC Sender Code Example:

msgData.Type = MSG_TYPE_RPC; // This tells the receiver it is an RPC
msgData.ID = 100; // This is the RPC ID to be executed
msgData.Parameters = parameterList;
List<string> remoteClients = new List<string>();
remoteClis.Add(otherMemberUserID);
remoteClis.Add(anotherMemberUserID);
remoteClis.Add(yetAanotherMemberUserID);
bool reliable = true;
// Send the RPC to multiple remote clients in a room
room.MessageTo(room.GetRoomID(), remoteClis, msgData.Encode(), reliable);

How To Execute RPC Sent From A Remote Client

The example below shows how to execute RPC commands sent from remote clients in the same room.

NOTE: msgData shown here is an example and it is not included in the client SDK.

RPC Receiver Code Example:

room.OnMemberMessage += OnRoomMemberMessage;

private void OnRoomMemberMessage(byte[] message)
{
  MessageData msgData = MessageData.Decode(message);
  switch(msgData.Type)
  {
    case MSG_TYPE_RPC:
      ExecuteRPC(msgData);
      break;
    default:
      // unknown message data type... 
    break;
  }
}

private void ExecuteRPC(MessageData msgData)
{
  switch(msgData.ID)
  {
    case RPC_CMD_HELLO:
      // Execute RPC SayHello here
      SayHello(msgData);
    default:
      // unknown RPC ID... 
    break;
  }
}

How To Invoke RCP On All Remote Clients In A Room

Sending an RPC command to all members of the room will allow you to execute an RPC command on all clients in the room.

NOTE: msgData shown here is an example and it is not included in the client SDK.

RPC Sender Code Example:

msgData.Type = MSG_TYPE_RPC; // This tells the receiver it is an RPC
msgData.ID = 100; // This is the RPC ID to be executed
msgData.Parameters = parameterList;
List<string> remoteClients = new List<string>();
remoteClients.Add(otherMemberUserID);
bool reliable = true;
// Send the RPC to all remote clients in a room
room.BroadcastTo(room.GetRoomID(), msgData.Encode(), reliable); 

How To Execute RPC Sent From A Remote Client Via Broadcast

The example below shows how to execute RPC commands sent from remote clients in the same room.

NOTE: msgData shown here is an example and it is not included in the client SDK.

RPC Receiver Code Example:


room.OnMemberBroadcast += OnRoomMemberBroadcast;

private void OnRoomMemberBroadcast(byte[] message)
{
  MessageData msgData = MessageData.Decode(message);
  switch(msgData.Type)
  {
    case MSG_TYPE_RPC:
      ExecuteRPC(msgData);
      break;
    default:
      // unknown message data type... 
    break;
  }
}

private void ExecuteRPC(MessageData msgData)
{
  switch(msgData.ID)
  {
    case RPC_CMD_HELLO:
      // Execute RPC SayHello here
      SayHello(msgData);
    default:
      // unknown RPC command ID... 
    break;
  }
}

The link to Diarkis C# client SDK documentation is here.

Diarkis enables massive multiplayer network communications.

Contact Us
このエントリーをはてなブックマークに追加

Recommendations

If you are interested in learning more about Diarkis, please contact us here.

Contact Us Request Documents
PAGE TOP