> ## Documentation Index
> Fetch the complete documentation index at: https://developers.strawberryfoundations.org/llms.txt
> Use this file to discover all available pages before exploring further.

# Introduction to the Strawberry Communication Standard

> This should give you a general idea what the Strawberry Communication Standard is about

# What is this?

The Strawberry Chat communication system is currently being rewritten.
In order to distinguish between the old system and the new system, we are now introducing the Strawberry Communication System (stbm).
This communication system forms a standard for Strawberry Chat, and possibly for other Strawberry Foundations projects in the future.

Currently we have 2 major versions of stbm.
Version 1 `(stbmv1)` is a legacy version and no longer receives any new major updates. We only offer support for a certain period of time.

Version 2 `(stbmv2)` is a new, revised version of our communication system.
This uses JSON to transfer messages via the user.
With our new communication standard, users can now program their own message builder and decide for themselves how a message should be displayed, regardless of how the server had actually formatted the messages.

There is also Version 2.1 `(stbmv2.1)` which adds support for message proxying, currently it is not available.

# What? Why? How?

You may wonder and ask yourself what even is this? Well, this is a way how 2 socket instances communicate with
each-other, this was primarily designed for Strawberry Chat to send data between the server and the client such as
username, badges and messages, but we decided to make a small guide on how to implement it into your client.

<Tip>JSON communication is also another name for our Strawberry Communication Standard v2 (`stbmv2`). You can learn more about it [here](/stbchat/stbm)</Tip>

# The Idea

The original concept for it was posted to our projects board on [GitHub](https://github.com/orgs/Strawberry-Foundations/projects/1?pane=issue\&itemId=44311144) on November 10th 2023
Please note that this is currently only available in German.

# Example code

<Info> This is a very basic example of JSON Communication which is used in Strawberry Chat </Info>

<CodeGroup>
  ```json JSON theme={null}
  {
      "message_type": "user_message", // Type of the message, usually user_message
      "username": "julian", // Username should be all lowercase and without spaces
      "nickname": "Julian The Great", // Nicknames can contain any UTF-8 character and spaces
      "badge": "👑", // Emoji
      "role_color": "\u001b[31m\u001b[1m", // This uses ANSI colors, example given here is red & bold
      "message": {
          "content": "Hello World!"
      }
  }
  ```

  ```python Python theme={null}
  # Receive code of the client
  def receive(sock):
      while threadFlag:
          try:
              message = sock.recv(2048).decode('utf-8')

              try: message = conv_json_data(message)
              except: message = message

              if message:
                  try:
                      try: message_type = message["message_type"]
                      except: message_type = "unknown"

                      if message_type == "user_message":
                      username    = message["username"]
                      nickname    = message["nickname"]
                      badge       = badge_handler(message["badge"])
                      role_color  = message["role_color"]
                      message     = message["message"]["content"]

                      if nickname == username:
                          fmt = f"[{current_time()}] {role_color}{username}{badge}:{CRESET} {message}"
                      else:
                          fmt = f"[{current_time()}] {role_color}{nickname} (@{username.lower()}){badge}:{CRESET} {message}"

                      print(fmt)

                  else:
                      message     = message["message"]["content"]
                      print(f"[{current_time()}] {message}")

              except Exception as e:
                  time.sleep(0.05)
                  message         = message["message"]["content"]
                  print(f"[{current_time()}] {message}")

          else: break

      except Exception as e:
          if experimental_debug_mode: print(f"{Fore.RED + BOLD}{Str[lang]['ConnectionInterrupt']}{Fore.RESET + CRESET}")
  pass
  ```
</CodeGroup>

# Supported versions in Strawberry Chat

<Warning>
  This only applies to Strawberry Chat, not other programs
</Warning>

See this chart below

|                     | v1.8.0 - v1.8.2 ![](https://img.shields.io/badge/Legacy-green) | v1.8.3 ![](https://img.shields.io/badge/Legacy-gray) | v1.9.0 ![](https://img.shields.io/badge/Stable-success) |
| ------------------- | -------------------------------------------------------------- | ---------------------------------------------------- | ------------------------------------------------------- |
| Standard `<=2.4.0`  | ✅                                                              | ✅                                                    | ❌                                                       |
| Standard `v2.5.0`   | ❌                                                              | ❌                                                    | ✅                                                       |
| Standard `>=v2.5.1` | ✅ (CM)                                                         | ✅ (CM)                                               | ✅ (CM)                                                  |
| Lite `<=v1.0.1`     | ✅                                                              | ✅                                                    | ❌                                                       |
| Lite `>=v1.1.0`     | ❌                                                              | ❌                                                    | ✅                                                       |
| Nano `<=v1.0.1`     | ✅                                                              | ✅                                                    | ❌                                                       |
| Nano `>=v1.1.0`     | ❌                                                              | ❌                                                    | ✅                                                       |
| Berryjuice-pico     | ✅                                                              | ✅                                                    | ❌                                                       |

<Tip>
  ### Compatibility Mode (CM)

  As of Client v2.5.1, we have added a feature that allows users to connect to old servers.
  This is called Compatibility Mode. To activate it you either have to add `compatibility_mode: true` to the respective legacy server entry or start the client with the `--compatibility-mode` flag!
</Tip>
