Larsson Posted May 1, 2025 Posted May 1, 2025 Hi, I am building a multi tenant solution and want to restrict traffic to specific clients. From what I understand we can only broadcast to everyone as of now? Will there be an option to be able to send to a specific client? I can think of these alternatives: Wait for implementation in Unigui Use javascript and a custom websocket solution Use vcl websocket on mainmodule (one fore each) so that we get single user Deploy once for every tenant Other alternatives? Regards, Fredrik. Quote
Larsson Posted May 1, 2025 Author Posted May 1, 2025 I just discovered BroadcastMessageSessions and I guess it can be used with UniSession.SessionId Anyone with samplecode/info? Nothing in the helpfile I am afraid. 1 Quote
andyhill Posted May 1, 2025 Posted May 1, 2025 Off memory this is how I make sure my tables "tblVolunteers" and "tblVolunteerLkUp" are refreshed after another app has edited their data using the Broadcast feature to notify. I decided to force MainForm to send the Broadcast via MainModule Ajax Event. MainForm receiving broadcast message procedure TMainForm.MainFormBroadcastMessage(const Sender: TComponent; const Msg: string; const Params: TUniStrings); var s: String; begin ////////////////////////////////////////////////////////////////////////////// if Msg = 'VolunteerUpdate' then begin if UniMainModule.tblVolunteers.Active = True then begin if UniMainModule.EditingVolunteerFlag = False then begin //////////////////////////////////////////////////////////////////////// s:= Params.Values['SID']; if UniSession.SessionID <> s then begin ////////////////////////////////////////////////////////////////////// // Volunteers try UniMainModule.tblVolunteers.Refresh; // REQUIRED FOR CALCULATED FIELDS UniMainModule.dsVolunteers.DataSet.Refresh; // REQUIRED FOR GRID except end; ////////////////////////////////////////////////////////////////////// // Volunteer LookUp try if UniMainModule.tblVolunteerLkUp.Active = True then begin UniMainModule.tblVolunteerLkUp.Refresh; // Sync end; except end; end; // SessionID end; // EditingVolunteerFlag end; // Active end; // VolunteerUpdate end; MainModule has tblVolunteers AfterDelete/AfterPost Events etc. to Notify MainForm procedure TUniMainModule.tblVolunteersAfterPost(DataSet: TDataSet); begin UniSession.AddJS('ajaxRequest('+MainForm.WebForm.JSName+', ''_VolunteerEdited_'', []);') end; MainForm AjaxEvent Send Broadcast procedure TMainForm.MainFormAjaxEvent(Sender: TComponent; EventName: string; Params: TUniStrings); begin //////////////////////////////////////////////////////////////////// if SameText('_VolunteerEdited_', EventName) then begin BroadcastMessage('VolunteerUpdate', ['SID', UniSession.SessionID]); Exit; end; ... Of course there are many ways to do this. 1 Quote
Sherzod Posted May 2, 2025 Posted May 2, 2025 Hello, 17 hours ago, Larsson said: Will there be an option to be able to send to a specific client? 17 hours ago, Larsson said: I just discovered BroadcastMessageSessions and I guess it can be used with UniSession.SessionId Anyone with samplecode/info? Nothing in the helpfile I am afraid. Yes, BroadcastMessageSessions allows you to target specific sessions by using their SessionId. However, it's important to keep in mind that a SessionId is only valid for the lifetime of the current user session — it's not a permanent identifier for a client or user. If you're building a multi-tenant system and want to send messages to specific users or tenants consistently, you’ll need to maintain a mapping between your user IDs (or tenant IDs) and active SessionIds. This way, you can use BroadcastMessageSessions dynamically by looking up the correct sessions at runtime. Would you mind clarifying what you mean by “specific client”? Are you referring to a unique user, tenant, or something else? This would help suggest the most suitable approach. 1 Quote
Hayri ASLAN Posted May 2, 2025 Posted May 2, 2025 On 5/1/2025 at 8:12 AM, Larsson said: Hi, I am building a multi tenant solution and want to restrict traffic to specific clients. From what I understand we can only broadcast to everyone as of now? Will there be an option to be able to send to a specific client? I can think of these alternatives: Wait for implementation in Unigui Use javascript and a custom websocket solution Use vcl websocket on mainmodule (one fore each) so that we get single user Deploy once for every tenant Other alternatives? Regards, Fredrik. We will share the code soon 4 1 Quote
Larsson Posted May 6, 2025 Author Posted May 6, 2025 Yes, this is what I want to accomplish. Will use a session table to keep track of them. Thanks for the feedback! Quote
emin Posted August 30, 2025 Posted August 30, 2025 I'm using Websocket, and I filter the message I send to all clients on the client side and display it to the relevant users. This isn't very efficient and consumes a lot of system resources. I need to send a message specifically to the relevant client. Can you share your code, Hayri? Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.