You are not logged in.
Hi,
I'm using Example 31 webSockets, projectChatServer ( simple SOA server using callbacks for a chat room) as base for my own chat program. How can I get info on active conections to server? when connected to webserver every user set a UserName, an then send messages to all other users, I would like to send a message to a specific user, so I need to identify other usernames...
In the sample code :
procedure TChatService.Join(const pseudo: string;
const callback: IChatCallback);
begin
InterfaceArrayAdd(fConnected,callback);
end;
procedure TChatService.BlaBla(const pseudo,msg: string);
var i: integer;
begin
for i := high(fConnected) downto 0 do // downwards for InterfaceArrayDelete()
try
fConnected[i].NotifyBlaBla(pseudo,msg);
except
InterfaceArrayDelete(fConnected,i); // unsubscribe the callback on failure
end;
end;
I would like to do something like
msg='DestinationUser;RealMessage'
separate msg in 'DestinationUSer' and 'RealMessage' (easy of course) and then do something like
for i := high(fConnected) downto 0 do
if fconnected[i].UserName = 'DestinationUser' then
fConnected[i].NotifyBlaBla(pseudo,'RealMesage');
Or something like
i = fconnected.findUserByName('DestinationUser' )
Fconnected[i].NotifyBlaBla(pseudo,'RealMesage');
I have been looking in the forum and I guess it should be something like
var
currSession: TAuthSession;
begin
for i := high(fConnected) downto 0 do // downwards for InterfaceArrayDelete()
begin
currSession := (fConnected[i] as TAuthSession);
currSession.UserName
...
But of course it doesn't work for fConnected...
As you can see I have no idea how to do it... Can you helpme please
(ps. Is there a way to search in the forum?, I had been reading a lot of post without luck)
Last edited by JuanK (2019-08-30 05:56:45)
Offline
Assuming you are using default framework authentication then you need to access servicecontext thread var to get the session information, you would do this when the user joins the chat service and store the user name or id together with the callback interface, something like this : gist
Offline
Thank you very much pvn0
That worked Great!!!
I follow your recommendation and defined fconnected as an array of records and store there the callback and the info I need to preserve.
Offline
Glad to be of help, if you changed the array definition then remember to replace the InterfaceArrayAdd, InterfaceArrayDelete etc.. calls as well as those only work on interface arrays.
Offline
Yes, I noticed that, also changed BlaBla as "procedure BlaBla(const Source:string; const Destination:string; msg: string);" to have Source User, Destination User and Message in different variables. Thank you again, also for responding so quick..
Offline