> For the complete documentation index, see [llms.txt](https://help.diarkis.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://help.diarkis.io/en/diarkis-client/samples/cpp/room_chat.md).

# room\_chat

### room\_chat Sample

#### Overview

The room\_chat sample is an interactive command-line program that demonstrates the Room Chat features of the Diarkis server. It allows users to join a room and exchange custom chat messages in real time, as well as retrieve the full chat history via a sync command.

The room\_chat sample showcases the following features:

* Joining a Room
* Sending custom chat messages to Room members
* Retrieving the full chat history (sync)
* Leaving a Room

#### 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](https://help.diarkis.io/en/getting-started/tutorial/setup-local-server).

#### Sample Arguments

Specify the following 3 parameters when launching the sample.

| Argument   | Description                                       |   |
| ---------- | ------------------------------------------------- | - |
| serverAddr | Specify the endpoint of the Diarkis server        |   |
| UID        | Specify the user ID to connect with as any string |   |
| clientKey  | Specify the client key as any string              |   |

Launch example:

```
room_chat.exe 192.168.1.123:7000 1111 AAAA
```

#### Explanation of the room\_chat 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 Room module using the Diarkis Module.

```cpp
// Setup Room module
diarkis->SetupRoom(false);
```

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, check the status with DiarkisRoomBase::IsJoin() until the Room join is complete.

```
diarkis->RandomJoinRoom(10, 60, 0, false);
DiarkisUtils::Print("Joining room...");

while (!diarkis->GetRoomBase()->IsJoin())
{
    std::this_thread::sleep_for(std::chrono::milliseconds(100));
    }
    DiarkisUtils::Print("Joined room.");
```

Once joined, the sample enters an interactive command loop. The user can type commands via stdin to interact with the room:

* /send/\<message> — Send a chat message to the room
* /sync — Retrieve the full chat history from the server. Results are printed via the OnRoomChatLog callback.
* /quit — Leave the room and exit the program
* /help — Show available commands

Execute DiarkisRoomBase::SendLeaveRoom() to request to leave the Room. In this sample, wait until leaving the Room is complete using DiarkisRoomBase::IsLeave().

```
// Leave the Room
diarkis->SendLeaveRoom();

while (!diarkis->GetRoomBase()->IsLeave())
{
    std::this_thread::sleep_for(std::chrono::milliseconds(100));
    }
    DiarkisUtils::Print("Left");
```

Demo complete

For more details, refer to [Overall Flow for Using Diarkis Module](https://help.diarkis.io/en/diarkis-client/diarkis-module#diarkis-module-usage-overview).

#### Notes

* On Windows, the sample sets the console to UTF-8 encoding to correctly handle Japanese and other multibyte characters in chat messages.
* Multiple clients can be run simultaneously from separate terminal windows to test room chat interactions.
* The /sync command retrieves the full chat history from the server. Results are displayed via the OnRoomChatLog callback.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://help.diarkis.io/en/diarkis-client/samples/cpp/room_chat.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
