Tutorial

Online in 10 minutes — a chat room

Connect two players and send messages between them.

Goal

Create a room, join it from a second client, and exchange chat messages via the event relay.

1. Wire up the signals

func _ready() -> void:
    MultiplayerService.welcomed.connect(func(_id): print("connected"))
    MultiplayerService.room_created.connect(func(_id, code, _p): print("share this code: ", code))
    MultiplayerService.room_joined.connect(func(_id, _c, _player, players): print("players: ", players.size()))
    MultiplayerService.event_received.connect(_on_event)
    MultiplayerService.configure("pk_your_public_key")
    MultiplayerService.connect_to_server("wss://spawnweaver.dev/connect")

2. Create or join a room

# Client A:
MultiplayerService.create_room("Alice")

# Client B (with the code A shared):
MultiplayerService.join_room("ABC123", "Bob")

3. Send and receive chat

send_event defaults to the room you're in, so you don't pass a room id.

func send_chat(text: String) -> void:
    MultiplayerService.send_event("chat", { "name": "Alice", "text": text })

func _on_event(event: String, data: Dictionary, _from: String) -> void:
    if event == "chat":
        print(data.name, ": ", data.text)

The relay excludes the sender, so echo your own line locally.

4. Run two players

In Godot: Debug → Run Multiple Instances (2), run your scene, create a room in one window and join by code in the other.

Full version: the Realtime Chat Room example in sdk/godot-gdscript/examples/chat_room/.