docjones Posted January 5, 2012 Posted January 5, 2012 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 Quote
thecrgrt Posted January 5, 2012 Posted January 5, 2012 For load balancing(maybe, just distributed load), I hope FastCGI was supported by UniGUI to do that. Quote
dionel1969 Posted January 5, 2012 Posted January 5, 2012 For load balancing(maybe, just distributed load), I hope FastCGI was supported by UniGUI to do that. First: I don't know much about balancing of applications, just read some text and I have an idea in theory. Second: I would divide the application into two modules: 1- Balancing Module (8087) with the appropiate algorithm and implementation of it. 2- Main Module running in 2 ports (60001 - 60002) (two instances I mean) Then people would connect to First Module and this would decide where to redirect. Is the same app, but divide into two parts. "Give to Caesar what belongs to Caesar." Quote
zilav Posted January 5, 2012 Posted January 5, 2012 Then, how can i do redirect, and terminate session ? or this is not possible ? Doing balancing inside UniGui app is weird, but if you desire... procedure TMainForm.UniButton1Click(Sender: TObject); begin UniServerModule.ServerMessages.TerminateTemplate.Text := '<script>location.href=''http://google.com''</script>'; Close; end; Quote
docjones Posted January 6, 2012 Author Posted January 6, 2012 Doing balancing inside UniGui app is weird, but if you desire... procedure TMainForm.UniButton1Click(Sender: TObject); begin UniServerModule.ServerMessages.TerminateTemplate.Text := '<script>location.href=''http://google.com''</script>'; Close; end; Thanks, this is exactly i want to do. now, if too users are connected to primary server, my unigui app can control user sessions and redirect to another host . and i can do the same on the secondary server. 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.