room_broadcast
room_broadcast Sample
Overview
The room_broadcast sample is a sample program that uses the Room and P2P functionalities of the Diarkis server. Two users connect to the same Room, communicate via relay through the Room, and then switch to P2P communication. The room_broadcast sample allows you to verify the following features:
Creating a Room
Joining a Room
Sending messages to Room members
Initiating P2P
Sending and receiving messages via P2P
Starting the Server in a Local Environment
Follow the tutorial to start the server used in the sample and launch the Diarkis server in your local environment.
Launching Diarkis Server in a Local Environment
Explanation of the room_broadcast Sample
Initialize the Diarkis runtime and Diarkis Module and connect to the Diarkis server. For details, refer to General flow of using the Diarkis module.
Initialize each functionality. In this sample, we use the Room module and P2P module, so initialize those functions using the Diarkis Module.
Join a Room using RandomJoin.
DiarkisRoomBase::RandomJoinRoom()
joins an existing Room if available, or creates a new Room if none is available. After sending the request to the server withDiarkisRoomBase::RandomJoinRoom()
, check the status withDiarkisRoomBase::IsJoin()
until the join is complete.Wait until the expected number of participants have joined the Room. In this sample, wait until 2 users have joined the same Room. You can request a list of the members in the Room by calling
DiarkisRoomBase::SendGetMemberIDs()
. The results can be obtained withDiarkisRoomBase::GetRoomMembers()
.Send a message to all users in the Room using the Room's Broadcast.
The Room owner executes
DiarkisRoomBase::SendStartP2PSync()
to notify the server to start P2P connections and obtain the connection address list of the members in the Room.When the Room owner executes
DiarkisRoomBase::SendStartP2PSync()
, P2P connection information is notified to all users in the Room viaDiarkisRoomBase::OnStartP2PSync()
, which triggers the start of hole punching.After successful hole punching, communication via P2P begins.
Execute
DiarkisRoomBase::SendLeaveRoom()
to request to leave the Room to the server. In this sample, wait until leaving is complete usingDiarkisRoomBase::IsLeave()
.Finalize For details, refer to General flow of using the Diarkis module.
Notices
To successfully perform hole punching, the client performing P2P must exchange addresses while in the same Room.
Prepare multiple clients and run them simultaneously to check the operation.
最終更新