room_broadcast
room_broadcast Sample
Overview
The room_broadcast sample is a demonstration program utilizing the Room and P2P features of the Diarkis server. It allows two users to connect to the same Room, conduct relay communication via the Room, then establish a P2P connection for direct communication. The room_broadcast sample showcases the following features:
Room creation
Joining a Room
Sending messages to Room members
Initiating P2P
Sending and receiving messages via P2P
Starting the Server in Your Local Environment
Execute the tutorial to start the server used in the sample and launch the Diarkis server in your local environment.
1. Launch Diarkis Server in Local Environment
Explanation of the room_broadcast Sample
Initialize the Diarkis runtime and Diarkis Module and connect to the Diarkis server. For more details, refer to Overall Flow for Using Diarkis Module.
Initialize the necessary functions. Since this sample uses the Room and P2P modules, initialize those functions using the Diarkis Module.
Join a Room using RandomJoin.
DiarkisRoomBase::RandomJoinRoom()
will join an existing Room if available, or create a new one if not. After sending a request to the server viaDiarkisRoomBase::RandomJoinRoom()
, check the status withDiarkisRoomBase::IsJoin()
until the Room join is complete.Wait until the expected number of participants join the Room. In this sample, wait until 2 users join the same Room. You can request the list of members in the Room by calling
DiarkisRoomBase::SendGetMemberIDs()
. The results can be obtained withDiarkisRoomBase::GetRoomMembers()
.Use Room Broadcast to send a message to all users in the Room.
The Room owner executes
DiarkisRoomBase::SendStartP2PSync()
to notify the server of the initiation of P2P connections and to retrieve a list of address connections for participants in the Room.When the Room owner executes
DiarkisRoomBase::SendStartP2PSync()
, P2P connection information is notified to all users in the Room viaDiarkisRoomBase::OnStartP2PSync()
, triggering the start of hole punching.Upon successful hole punching, communication via P2P begins.
Execute
DiarkisRoomBase::SendLeaveRoom()
to request to leave the Room from the server. In this sample, wait until leaving the Room is complete usingDiarkisRoomBase::IsLeave()
.Termination For more details, refer to Overall Flow for Using Diarkis Module.
Notes
To successfully achieve P2P hole punching, the clients must be in the same Room and exchange addresses.
Please prepare multiple clients and execute them simultaneously to verify operation.
Last updated
Was this helpful?