How To Update A Numeric Room Property And SynchronizeDiarkis Room Module

 
The Room module allows you to have multiple remote clients join and share a virtually created room to exchange messages freely. Room module can also be used as an RPC broker for remote clients to exchange RPC commands using its broadcast and messaging.

Setting Up Room Module

The Room module is network protocol agnostic, but it needs to have a network client passed to it.
We will explain how to set up a room module instance with Diarkis TCP or UDP client.

Setting Up With Diarkis UDP Client

Setting Up With Diarkis TCP Client

How To Create A Room

With the Room module, you may create rooms with a fixed number of allowed members with optional settings for the room. OnCreate is raised when you invoke this method. If a UDP client is used, the message is sent as a RUDP.

How To Join A Room

To join a room, you need the room ID of the room. You will probably need to store the room IDs externally or use Match Maker to share room IDs. Also, we recommend your message include the sender’s user ID and other necessary information so that the recipients may detect who has joined and behave accordingly. When you join a room, OnJoin will be raised. Other members’ clients of the room will raise OnMemberJoin.  If a UDP client is used, the message is sent as a RUDP.

Detecting A New Member

When a new member joins a room, the OnMemberJoin event is raised. Below is an example of how to handle the event:

How To Leave A Room

Leaving a room will raise OnLeave and the other members’ clients will raise OnMemberLeave if the leave was successful. We recommend your message include the sender’s ID and other necessary information so that the recipients may detect which member has left the room and behave accordingly. If a UDP client is used, the message is sent as a RUDP.

Detecting A Member Leaving

When a member leaves the room, the OnMemberLeave event is raised. Below is an example of how to handle the event:

Join A Random Room Or Create A New Room If No Room Is Available

If you simply want to have your client join or create a room randomly, use this method. The event raised by the method is the same: OnJoin/OnMemberJoin or OnCreate. If a UDP client is used, the message is sent as a RUDP.

How To Broadcast A Message To All Members Of Room

The broadcast method will send a message to all members of the room including yourself. The message will be received by OnMemberBroadcast. We recommend your message includes the sender’s user ID and other information so that the recipients may detect who has sent the message and behave accordingly.

How To Receive Broadcast Messages

When other members send broadcast messages, the OnMemberBroadcast event is raised. Below is an example of how to handle the event:

How To Send A Message To Selected Members Of Room

You may send a message to selected members of the room instead of all members. The message will be delivered by OnMemberMessage. We recommend your message includes the sender’s user ID and other information so that the recipients may detect who has sent the message and behave accordingly.

How To Get Properties Of A Room

You may retrieve properties of the room you are in by providing property names. To read the retrieved properties, you must listen to OnGetProperties. All properties are byte arrays. If a UDP client is used, the message is sent as a RUDP.

How To Update Properties Of A Room

You may update the properties of the room you are in. All property values MUST be byte arrays.Calling UpdateProperties will raise OnUpdateProperties.  If a UDP client is used, the message is sent as a RUDP.

How To Synchronize A Numeric Room Property

By using room property, you may share and synchronize numeric room properties.
The examples below will explain how to manage and synchronize a numeric room property with members of your room.

How To Set Up Synchronization Of A Numeric Room Property Changes

The example below explains how to set up an event listener to synchronize the numeric room property value with all members of the room.

How To Initialize A Numeric Room Property

Typically the user client that creates the room initializes the numeric room property.

How To Update A Numeric Room Property And Synchronize

You may increment or decrement a numeric room property and auto-synchronize with the other members of the room.

How To Synchronize A Numeric Room Property As A New Member

hen a new member joins the room, the new member client needs to retrieve the current value of the numeric room property.

How To Obtain Other Members’ IDs and The Owner’s ID

You may retrieve a list of member IDs along with the owner ID.

Conclusion

The concept of Room is one of the most fundamental concepts of real-time appplications.
Diarkis Room module is extremely flexible and can be adapted to perform various operations making it more than the basic function of real-time appplications.

Contact us

For inquiries about Diarkis introduction, employment entry, etc., click here.