Un suscriptor recibe eventos proporcionando primero los temas (también conocidos como canales) en los que está interesado. A continuación, el suscriptor recibirá todos los eventos publicados en ese tema.
Para recibir eventos de un tema, el suscriptor primero debe suscribirse a ese tema.
Cliente WAMP
procedure OnMessageEvent(Connection: TsgcWSConnection; const Text: string);
begin
ShowMessage(Text);
end;
oClient := TsgcWebSocketClient.Create(nil);
oClient.Host := '127.0.0.1';
oClient.Port := 80;
oClientWAMP := TsgcWSPClient_WAMP.Create(nil);
oClientWAMP.Client := oClient.
oClientWAMP.OnMessage := OnMessageEvent;
oClient.Active := True;
// Subscribe to topic after successful connect
oClient.Subscribe('myTopic');
WAMP Server
procedure OnSubscriptionEvent(Connection: TsgcWSConnection; const Subscription: string);
begin
ShowMessage('Subscribed: ' + Subscription);
end;
oServer := TsgcWebSocketServer.Create(nil);
oServer.Port := 80;
oServerWAMP := TsgcWSPServer_WAMP.Create(nil);
oServerWAMP.OnSubscription := OnSubscriptionEvent;
oServerWAMP.Server := oServer;
oServerWAMP.Active := True;