This is the multi-page printable view of this section. Click here to print.

Return to the regular view of this page.

JSON Server

    The JSON Server remote opens a TCP port through which clients can exchange JSON messages with mAirList. Unlike the TCP Server, the received data is not executed as commands. Instead, it is passed to background scripts, which can process it and send replies. This makes it possible to implement custom protocols.

    Configuration

    In the configuration app or Control Panel, go to Remote Control and add an interface of type JSON Server (Network category).

    • Bind IP: The local IP address(es) to listen on, separated by commas. Leave empty to listen on all network interfaces.
    • Port: The TCP port to listen on. The default is 9303.

    Protocol

    Each message is a JSON document, encoded as UTF-8 and terminated by a null byte (ASCII 0). Messages that are not valid JSON are ignored.

    Scripting

    The following event handlers are available in background scripts:

    procedure OnJSONServerRemoteClientConnect(Remote: IJSONServerRemote; ClientID: cardinal);
    procedure OnJSONServerRemoteClientDisconnect(Remote: IJSONServerRemote; ClientID: cardinal);
    procedure OnJSONServerRemoteClientData(Remote: IJSONServerRemote; ClientID: cardinal; Data: IPersistentStorage);
    procedure OnJSONServerRemoteClientDataObject(Remote: IJSONServerRemote; ClientID: cardinal; Data: IPersistentObject);
    

    OnJSONServerRemoteClientDataObject is only called when the received document is a JSON object (rather than an array or a single value).

    To send data, use the following methods of the Remote object (or JSONServerRemote(<index>)):

    • SendTo(ClientID, Data) – send to a single client,
    • Broadcast(Data) – send to all connected clients,
    • BroadcastExcept(ClientID, Data) – send to all clients except the specified one.