Register a socket.io transport and bind a route
A socket.io transport needs no type-specific configuration beyond itsid.
The route bound to it carries the namespace declaration:
The exact declaration syntax depends on the language and generated SDK. The
following language-neutral form shows the declaration:
Connect to a namespace
A client connects to the namespace declared by the route. The Kernel checks the service-wide and namespace access policies during the connection handshake. If either policy rejects the user, the connection is refused. The namespace is unavailable while no running service owns it. Stopping the owning service disconnects existing sockets from that namespace. Future connections are rejected until the service is started again.Receive an event
Only event names listed inevents are forwarded to the service. Events that
are not declared are ignored by the Kernel.
The event sent to the service is the SocketEvent message described in
Protocol. Its fields are:
The Kernel does not impose an application schema on
payload. Define the
payload shape between your client and service, then decode and validate it in
the service. Since the payload is an array, an event with one object argument
is represented conceptually as:
user value.
Send an event
The service sends events using emit instructions. An emit instruction contains:
The event handler can return one or more emit instructions in its response.
This is the portable request/reply form. For WASM services, it is the normal
way to emit in response to an incoming event because the handler cannot push
an event spontaneously. A gRPC service can also use the Host’s emit
capability when it needs to send an event outside the current handler call.
For a directed event, set
target to the receiving socket’s ID. For a
namespace broadcast, leave target empty:
payload must contain a
JSON array of arguments. An empty payload emits an event with no arguments.
Access control
The Kernel evaluates access at both connection and event time:- The service-wide policy must allow the user.
- The namespace policy must allow the user.
- If the event has an entry in
event_access, that event policy must also allow the user.
error event to that socket. The error identifies whether authentication is
required or the user is forbidden. The event is not forwarded to the service.
See Access control for the policy model.
Namespace conflicts and lifecycle
A namespace can have only one owning route at a time. If another running service already owns the namespace, the Kernel does not connect the new route. The namespace conflict affects only that registration: the service still runs, but the Kernel marks itdegraded. Other non-conflicting routes can
remain available. Resolve the conflict and re-register the route to claim the
namespace.
Stopping a service releases its namespace ownership and disconnects all
sockets connected to that namespace. Starting the service again — or
re-registering the route — replaces the owner and lets clients connect again.
Event handling checklist
Before loading the service, verify that:- the namespace begins with
/and is unique to the service; - every event the service expects is listed in
events; - client and service agree that each payload is a JSON array of arguments;
- payloads are validated before the service uses them;
- namespace and event access policies protect the intended users; and
- emitted events use the correct namespace and target.