Hi all.
first, sorry for my poor english
I'm playing with unigui, and i'm trying to balance user sessions into two unigui applications (hosted on same or diferent server).
when user connect to primay server (localhost:8077), and sessions count >n , then i want terminate the user session, and redirect to second server like (localhost:8088).
this is the code.
Mainmodule.
type
TUniMainModule = class(TUniGUIMainModule)
procedure UniGUIMainModuleCreate(Sender: TObject);
procedure UniGUIMainModuleDestroy(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
Intime:tdatetime;
Session:TUniGuiSession;
Redirect:boolean;
end;
implementation
{$R *.dfm}
uses
UniGUIVars, ServerModule;
//when session starts.
procedure TUniMainModule.UniGUIMainModuleCreate(Sender: TObject);
begin
Intime:=now;
Session:=UniSession;
Redirect:=false;
UniServerModule.newsession(Self);
end;
//when session end.
procedure TUniMainModule.UniGUIMainModuleDestroy(Sender: TObject);
begin
UniServerModule.EndSession(Self)
end;
ServerModule
TUniServerModule = class(TUniGUIServerModule)
private
{ Private declarations }
procedure KillSession;
protected
procedure FirstInit; override;
public
{ Public declarations }
sessioncount:integer;
procedure NewSession(MModule: TUniMainModule);
procedure EndSession(MModule: TUniMainModule);
end;
implementation
{$R *.dfm}
uses
UniGUIVars;
Procedure Uni_Redirect(Sesion:TUniGUISession;Url:string);
var Cad:string;
Begin
Cad:='location.href='''+url+'''';
Sesion.AddJS(Cad);
End;
procedure TUniServerModule.NewSession(MModule: TUniMainModule);
Begin
//add session count.
inc(sessioncount);
if sessioncount>2 then begin //if > max allowed, then redirect.
MModule.Redirect:=true;
Uni_Redirect(Mmodule.Session,'http://localhost:8088');
end;
End;
procedure TUniServerModule.EndSession(MModule: TUniMainModule);
Begin
Dec(sessioncount);
End;
If i do a redirect (uni_redirect) on new session, then url redirect is not working
and, if i try to redirect on mainform.create , then redirect is working, but can't terminate the session
procedure TMainForm.UniFormCreate(Sender: TObject);
begin
if UniMainModule.Redirect then begin
Uni_Redirect(UniSession,'http://localhost:8088');
//Unisession.UniApplication.Terminate;// can't do this, becouse not redirected.
end;
end;
Then, how can i do redirect, and terminate session ? or this is not possible ?
Thanx