Channels & Messages
How events are addressed, why a channel might never open, and the one asymmetry that shapes multi-display applications.
Table of Contents
What a Channel Is
An SBIO channel is a named, unidirectional pipe between your application and one sbengine
instance. Your application opens one end; the engine opens the other.
| Direction | Opened with | Carries |
|---|---|---|
| Input | AddInputChannel(name) |
Events from the engine to your application |
| Output | AddOutputChannel(name) |
Events from your application to the engine |
An application talking to one display typically opens one of each. An application driving two displays opens one output channel per engine, and — because of the asymmetry described below — usually a single shared input channel.
Naming a Channel
The name must match the Storyboard application name: the value stored in the app/n node of
the .gde model.
It is not:
- the
.gdefilename storyboardAppNameinStoryboardConfiguration.json(which is the filename)- the project folder name
These are often different, and nothing reconciles them. In the MultiScreen demo the .gde files
are Dashboard.gde and Detail.gde, while the channel names are dashboard_ui and detail_ui.
| Constraint | Value | On violation |
|---|---|---|
| Maximum length | 25 characters (GRE_IO_MAX_NAME_LEN) |
Warning logged; SBIO never creates the channel |
| Must be non-empty | — | ArgumentException at AddInputChannel / AddOutputChannel |
| Must be unique per direction | — | ApplicationException |
| Must match the engine's application name | — | Channel never opens; startup blocks |
Tip
Keep the channel name and the application name identical to something short and obviously
paired — dashboard_ui for the dashboard screen. The 25-character limit is generous until
someone names a channel after a fully qualified type.
Channel Ids and Routing
Channels are numbered per direction, in the order added, from zero:
client.AddOutputChannel("dashboard_ui"); // outbound id 0
client.AddOutputChannel("detail_ui"); // outbound id 1
client.AddInputChannel("multiscreen_backend");
The outbound id is how a message says which engine it is for:
public partial class DetailUpdate
{
protected override void OnInit()
{
Message.ChannelId = 1; // detail_ui
}
}
SendEvent looks the id up in the outbound channel list. A generated model's constructor leaves
ChannelId at zero, so every message in a multi-display application needs its channel stamped
— otherwise all of them go to whichever engine happens to be channel 0.
The demos centralise these as constants rather than scattering literals:
internal static class MultiScreenChannels
{
public const string Backend = "multiscreen_backend";
public const string DashboardApp = "dashboard_ui";
public const string DetailApp = "detail_ui";
public const int DashboardChannel = 0;
public const int DetailChannel = 1;
}
Because the ids are positional, the constants and the AddOutputChannel call order must agree.
Adding a channel in the middle of the list renumbers everything after it.
The Inbound Asymmetry
This is the single most consequential behaviour on this page.
A received message does not record which channel it arrived on. The SBIO callback that
delivers events carries the event name, format and data — but not the channel handle — so
StoryboardMessage.ChannelId is meaningless on an inbound message.
| Outbound | Inbound | |
|---|---|---|
| Channel selected by | Message.ChannelId |
n/a |
| Sender identifiable | Yes — you chose the channel | Only by event name |
For a multi-display application this means: distinguish screens by event name, not by channel.
The MultiScreen demo declares dashboard_command and detail_command as separate events and has
both screens send to one shared multiscreen_backend channel. Opening two inbound channels would
not help, because the arriving message would not say which one it came from.
Sending
var update = new ThermostatUpdate();
update.CurrentTemperature = 58;
update.TargetTemperature = 70;
client.SendEvent(update.Message);
Two overloads exist — one taking a StoryboardMessage, one taking a StoryboardViewModelBase.
Both resolve the channel the same way, from the message's ChannelId.
Their failure behaviour differs, and the difference matters:
| Overload | Unknown channel id | Channel exists but send fails |
|---|---|---|
SendEvent(StoryboardMessage) |
Logged, message dropped | Return value ignored |
SendEvent(StoryboardViewModelBase, string) |
Logged, message dropped | Terminates the process |
The second is deliberate: an application whose UI has stopped accepting updates is showing stale data to an operator, which is treated as unrecoverable rather than something to limp along with.
Note
The target parameter on the model overload is accepted but not transmitted. It exists for
application-side routing conventions.
Receiving
Through the dispatcher, which is the idiomatic form:
Dispatcher.Default.RegisterCallback<StoryboardEventArgs>(HandleInputMessage, client);
void HandleInputMessage(object model, StoryboardEventArgs e)
{
switch (e.Message.Name)
{
case ChangeBrightness.Name:
e.Message.GetObject<ChangeBrightness>().UpdateModel();
break;
case Shutdown.Name:
ApplicationContext.Exit();
break;
}
}
Or directly on the event, in which case the handler runs on the listener thread:
client.MessageReceived += (s, e) => { /* not on your main thread */ };
GetObject<T> uses the generated factory to build the typed model. It returns null if no
metadata was supplied to the client constructor, and throws if the event name is not in the
metadata — which happens when the generated file is stale relative to custom.evt.
Switching on Name against the generated Name constants keeps the dispatch table honest: rename
an event in Designer, regenerate, and the case label fails to compile.
Failure Modes
| Symptom | Cause | Fix |
|---|---|---|
| Startup hangs; "has not opened after N seconds" in the log | Channel name does not match the engine's application name | Check the app/n node in Designer |
| Channel never opens, no warning about the name | Name longer than 25 characters | Shorten it |
| Updates reach the wrong display | ChannelId left at zero |
Stamp it in OnInit |
| Cannot tell which screen sent an event | Inbound messages carry no channel | Use distinct event names per screen |
SendEvent logs "names output channel N, which does not exist" |
Stale or unset ChannelId, or channel added after the id was captured |
Check AddOutputChannel ordering |
| Process exits on send | Channel accepted the message but SBIO rejected it | Check the engine is alive and the format matches |