WAMP | Abonnés

Un abonné reçoit des événements en fournissant d'abord les sujets (alias canaux) qui l'intéressent. Ensuite, l'abonné recevra tous les événements publiés sur ce sujet.

Pour recevoir des événements d'un sujet, l'abonné doit d'abord s'abonner à ce sujet.

 

Client 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');

 

Serveur WAMP

 


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;