room_broadcast
room_broadcast Sample
Overview
The room_broadcast sample is a demonstration program that uses the Room and P2P functionalities of the Diarkis server. Two users connect to the same Room, conduct relay communication through the Room, and then switch to P2P communication. This sample provides the following features to verify:
Creation of a Room
Participation in a Room
Sending messages to Room members
Initiation of P2P
Sending and receiving messages through P2P
Starting the Server in a Local Environment
Execute the tutorial to start the server used in this sample and initialize the Diarkis server in your local environment.
1. Launch Diarkis Server Locally
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 process of utilizing the Diarkis module.
Initialize the necessary functions. Since this sample uses the Room and P2P modules, initialize those functions using the Diarkis Module.
Enter a Room using RandomJoin. If a joinable Room already exists,
DiarkisRoomBase::RandomJoinRoom()
will join it; otherwise, it will create a new Room. After sending a request to the server withDiarkisRoomBase::RandomJoinRoom()
, check the state until the Room join is complete usingDiarkisRoomBase::IsJoin()
.Wait until the expected number of people have joined the Room. In this sample, wait until 2 users have joined the same Room. You can request the list of members participating in the Room by calling
DiarkisRoomBase::SendGetMemberIDs()
, and the result can be retrieved withDiarkisRoomBase::GetRoomMembers()
.Send a message to all users participating 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 address list of the connection destinations of the members participating in the Room.When the Room owner executes
DiarkisRoomBase::SendStartP2PSync()
, P2P connection information is notified to all users in the Room throughDiarkisRoomBase::OnStartP2PSync()
, triggering the start of hole punching.After successful hole punching, communicate via P2P.
Execute
DiarkisRoomBase::SendLeaveRoom()
to request leaving the Room from the server. In this sample, wait until leaving the Room is complete usingDiarkisRoomBase::IsLeave()
.Termination process For more details, refer to Overall process of utilizing the Diarkis module.
Notes
To successfully perform P2P hole punching, the clients wishing to perform P2P must be in the same Room and exchange addresses.
Please prepare multiple clients and execute them simultaneously to verify functionality.
Last updated