WAMP | 订阅者

订阅者首先提供其感兴趣的主题(又称频道)来接收事件。之后,订阅者将接收发布到该主题的任何事件。

要从主题接收事件,订阅者首先必须订阅该主题。

 

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 服务器

 


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;