TsgcWSPClient_sgc › Methods › Subscribe

Subscribe Method

Subscribes the client to a custom channel.

Syntax

procedure Subscribe(const aChannel: String; const aGuid: String = '');

Parameters

NameTypeDescription
aChannelconst StringName of the channel to subscribe to.
aGuidconst StringOptional Guid of the target server-side sgc protocol instance. Leave empty to use the default.

Remarks

Sends a subscribe request for the given channel. When the server confirms the subscription, the OnSubscription event fires. After subscribing, messages published to the channel are delivered through OnEvent.

aChannel is matched by the server as an exact string. MQTT-style wildcards such as topic1/# or topic1/+ are not interpreted: they are treated as literal characters in the channel name, so a client subscribed to topic1/# does not receive messages published to topic1/sensorA.

To subscribe to several channels in one call, separate them with a comma:

oProtocol.Subscribe('topic1/a,topic1/b,topic1/c');

The comma is the list delimiter, so it cannot be part of a channel name. The same comma-delimited syntax applies to UnSubscribe and to the channel, exclude and include arguments of Broadcast and Publish.

The server can optionally expand a channel argument using mask matching (* and ?, not MQTT syntax) instead of an exact match. See TsgcWSPServer_sgc.UseMatchesMask. For real MQTT topic filters with # and + semantics, use TsgcWSPClient_MQTT instead.

Example

oProtocol.Subscribe('news');

// multiple channels in one call
oProtocol.Subscribe('topic1/a,topic1/b,topic1/c');

Back to Methods