Form my main app I want to send some messages to the connected clients. I’ve implemented the eventhandler / event repository.
However most samples are built around events being triggered in the Implementation unit. I know there is a boradcast server but adding another server for some simple messages seems overhead.
What is the preferred way to send a message to all connected clients?
I have done this from the fServerDataModule but it does not seem right:
var
ev: IMy_Writer;
i: Integer;
AList: TStringList;
begin
AList := TStringList.Create();
ROSessionManager.GetAllSessions(AList);
for i := 0 to AList.Count-1 do
begin
ev := (ROEventRepository as IPlayerEventSink_Writer);
ev.ExcludeSender := False;
ev.MyProc(StringToGUID(AList[i]),MyParam);
end;
Second question is where to place the RegisterEventClient for this scenario. I’ve done that in the RORemoteDataModuleActivate now which works but the unregister in the Deactivate does not work.
procedure THTTPChatServerMainForm.bbWarnShutdownClick(Sender: TObject);
var reason : string;
begin
reason := 'The system administrator will reboot the server in 5 minutes.'#13#13+
'Please close your applications and save your work.';
if InputQuery('Shutdown Reason', 'Reason', reason)
then (EventRepository as IHTTPChatServerEvents_Writer).OnSystemShutdown(EmptyGUID, 5, reason);
end;
RegisterEventClient usually should be put to the Login method of the LoginService service