WAMP | Subscribers

구독자는 먼저 관심 있는 토픽(채널)을 제공하여 이벤트를 받습니다. 이후 구독자는 해당 토픽에 게시된 모든 이벤트를 받습니다.

토픽에서 이벤트를 수신하려면, 구독자는 먼저 해당 토픽을 구독해야 합니다.

 

WAMP Client

 


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;