You are not logged in.
Pages: 1
Is there a way to limit the number of client.
On my server app I have allow connect only for a number of client, for example only 5 clients. If other clients try to connect my server app must reject the connection.
Is there a simple way to do it?
regards
Offline
just an idea..
maybe you can check number of active session in a callback procedure?
Offline
just an idea..
maybe you can check number of active session in a callback procedure?
I don't have idea about I do it. Can you indicate the page of documentation where I can found information about it?
Thanks
Offline
in documentation you can search "14.1. Publishing a service on the server" that explain all.
you can see an example in MainDemo (see AuditTrail logging).
Offline
Are you talking about active session number limitation?
You can use the TSQLRestServer.OnSessionCreate event to abort if the total count is too much, by returning true.
The number of active session (excluding the current one) is stored in Server.Stats.ClientsCurrent.
Offline
I noticed that if a client crash-stops, the Server.Stats.ClientsCurrent will show an incorrect number (ie it doesn't know the previous connection crashed).
Is there a way to purge old/invalid connections from the Server.Stats ?
Offline
I think the problem I am having is that checking for deprecated sessions only occurs if there are any currently active sessions.
Problem:
I am checking ClientsCurrent in the TSQLRestServer.OnSessionCreate method...
function TMyApp.DoOnSessionCreate(Sender: TSQLRestServer; Session: TAuthSession; Ctxt: TSQLRestServerURIContext): boolean;
var
lClientsCurrent: integer;
begin
lClientsCurrent:= Sender.Stats.ClientsCurrent;
result:= lClientsCurrent >= fMyMaxConnections;
end;
but the check for inactive sessions only occurs once a session has been created (note TSQLRestServer.SessionAccess only gets called if Ctxt.URISessionSignaturePos <> 0)...
function TSQLRestServer.SessionAccess(Ctxt: TSQLRestServerURIContext): TAuthSession;
...
fSessionsDeprecatedTix := tix; // check deprecated sessions every second
for i := fSessions.Count-1 downto 0 do
if tix>TAuthSession(fSessions.List[i]).TimeOutTix then
SessionDelete(i,nil);
So if I limit MyMaxConnections to say 2, and then both of these clients crash-stop, a third connection attempt will get declined (ClientsCurrent >= fMyMaxConnections), but the old crashed sessions will never get deleted because TSQLRestServer.SessionAccess never gets called as I don't have any real active sessions.
Solution:
I am thinking I can create my own descendant of TSQLRestServer to give me access to the protected session methods and then check for deprecated sessions during OnSessionCreate, or to let the client connect, then check the session count and use a callback to force a disconnect if needed, or is there a better way to do this?
Or have I missed something?
Offline
Please check https://synopse.info/fossil/info/b4c6b71914
Don't forget to call Sessions.Lock/Unlock between the method call.
Offline
Thanks ab - working well.
(I noted a comment of the "inc(result)" line in SessionDeleteDeprecated and wasn't sure why too - I'll keep an eye on that thread....)
Offline
Pages: 1