Jump to content

What is Session in UniGui?


elGringo

Recommended Posts

Hello, guys, professionals! I don't have a lot experience in web development, so I want to ask simple questions!

 

-What is Session in UniGI? Is that some file on the server like in PHP ? Or is that copy of programm, started on the Server?

 

-How to Use it? Basic, popular examples of using it? I know one - to Add JS UniSession.AddJS('alert(''This is message from JS '')');

 

Could you explain basic things about session?

post-2378-0-77582200-1455631536_thumb.jpg

Link to comment
Share on other sites

I'll try to describe it as simple as I can.

 

When a user loads unigui app on his browser a session is started for this user, let's say as a channel of conmunication. Everything that is placed on your server module let's say a constant is common for all sessions for all users, on the other hand the properties thar are placed on mainmodule are "alive" only for the current session. When a session is restarted mainmodule reinitialized.

 

That's for a start. You must experiment a little bit for better understanding.

 

I hope this was helpful a little bit for you

Link to comment
Share on other sites

I believe that at this forum, a lot of people including me had little or not at all experience in web development because we came from delphi world. And now, thanks to Farshad and his team, we create sophisticated web applications. The result came from a lot of experiment with unigui product and of course read almost all posts of the forum, yes "all". As you know my friend "No pain, no gain" :D

 

Regards

  • Upvote 1
Link to comment
Share on other sites

This is how I assume things work:

 

When you initiate the app, an instance of mainmodule is created,

and a unique session constant is created and associated with that instance,

and this constant is also stored in the browser.

 

As you go on using the instance, a check is performed for every request,

comparing the browser stored constant with the mainmodule constant,

and as long as these match, the session is considered alive.

 

Also, a session timeout timer is running at the servermodule, and if this

gets triggered, the session constant is cleared, effectively blocking any

further requests from the browser, and the servermodule then reports

the timeout and offers a reload to the browser.

 

After using Unigui for a while, I do not really see such a great need for

documentation. I know it sounds weird, but it is almost a good thing that

you have to work a bit in the beginning, having a somewhat steep learning

curve, because you then learn the stuff in a practical way, and that sticks.

  • Upvote 2
Link to comment
Share on other sites

In web development sessions has two meaning:

 

1. Session is an instance for the application with unique ID, it's for one users, for one browser (each tab on chrome has new session even if the same user is logged), each session has it's memory and events dedicate to it, and no session will see other sessions data.

 

session usually has a timeout time (usually 20 min), and if user will be idle for this amount of time, the session will be terminated and all data (not saved) will be lost.

 

2. Session object, it's an object dictionary for each session instance, and it could be access within the application for the same (session id only), for example you can use it as

 

Session['MyUser'] := 'ABC', so you can read it from other pages

 

but in UniGui you declare variables inside "TUniMainModule" and it will be access for the same users on all forms.

 

in both cases, if session timeout (expired) all data will be lost.

Link to comment
Share on other sites

Mohhamed! Thank you for such detailed answer!!!

 

Before asking that - I also thought that its some copy / instance of the programm but I have read some topics of "What is session" for different technologies, like PHP, and decided to ask here.

 

So, session is instance - clear for me, thank you.

 

As for the second point - if i understand correct - lets take real example from Demos 

 

C:\Program Files (x86)\FMSoft\Framework\uniGUI\Demos\Desktop\SessionTimeout

 

We declare in MainModule variable

AllowTerminate : Boolean; 

and call it in Main

procedure TMainForm.UniCheckBox1Click(Sender: TObject);
begin
  UniMainModule.AllowTerminate:=UniCheckBox1.Checked;
end; 

 Is that good example for your 2 point? 

 

And in other instance there will be another variable AllowTerminate - if I understand you correct?

 

And if I want to share some variable beetwen sessions - if I understand correct - I should keep it on the ServerModule? 

Link to comment
Share on other sites

Hi elGringo, Glad I help to clear some things :)

 

regarding your question regarding AllowTerminate  variable, this  will effect point 1 & 2, because it will not the let session terminate when it's reach it's time out, it's used to extend the session for another perid of time, look at OnSessionTimeout in UniGUIMainModule:

procedure TUniMainModule.UniGUIMainModuleSessionTimeout(ASession: TObject;
  var ExtendTimeOut: Integer);
begin
  if not AllowTerminate then
  begin
    ExtendTimeOut:=15000;  // extend session for another 15 seconds
  end;
end;
Link to comment
Share on other sites

I agree, my example is for both 1&2))) Just if it would be any other variable than it will not exist after we will destroy the instance, as I understand.

 

Ok theme is almost clear for me - thank you Mohhamed and All for attention!!!

 

Other details in experiments and practice!

Link to comment
Share on other sites

Oscar, Mohhamed, Delphidude, Farshad, skepsis, and how do you think - what is normal practice for SessionTimeout Management in real Application?

 

I tested simple Application for 15 hours with this code above and it was working. Server responded the answer.

 

In real Application - how is it better to manage SessionTimeout

 

- to set it to 24 hours for example?

 

-or to set it endless how in the example above?

 

Because on the one hand it's not good when Application Terminated when user is working.

 

On another hand as I understood when user close the tab application terminated automatically.

 

Then endless Session seems to be the best variant?

Link to comment
Share on other sites

Good I will talk by my experience:

 

Users are a lot of .... people, they arrives on his work place, turn on his computers, log on in the web app, and goes to breakfast, drink terere or cafe, o small talk with the secretary, and when a customer arrives sit down on this place and want o use the web app, and surprise.....a timeout error occurs...and of course they complain.

 

That's because I implement a timer that every 5 mins take a call to the server to do something, sometimes read a database table of messages to search if they are any for the current user o wherever else. This process maintain alive his session for ever.

 

But sometimes the connection to the server is lost by for example for a internet down, normally on a branch on other city. Then a timeout is needed to clean up session temporary files, database connections, a so on.

 

When a user executes a report that takes to long to respond (normally when generate pdf file to publish to) the session must keep alive until finish the generation and ever more.

 

I put a big button to logout to all pages to suggest users to push it when they want to close app, but never use it, always use the red close button from browser windows. Then a timeout process is needed to do in this case. I notice that UniGui now have a event when this occurs.

 

Last thing, you developers must to be very carefull when use database transactions to update data with a crud (database record maintenance). The transaction must start and finish in the same event (buttonOnClick, OnKeyPress, etc.) if you left the transaction active between ajax call probably you wil cry later because user can swear that he update the data, but data is gone from database because never occurs a commit. If a timeout occurs in this time the could be happen.

 

I always be not satisfied with the actual session model of UniGui. I understand that the point is to be closer than Desktop/VCL apps is working but in web world could not be the best model. I never talk with Farshad about this because I think they have more importans things to do and there are more urgents. But I think that in a future of UniGui must have a way to implement a pool of sessions instead of create a session for every user that browse a page.

  • Upvote 2
Link to comment
Share on other sites

Wow! That is very detailed answer, Oscar!!!

 

So, if to assume your practice - best practice will be

 

-keep session alive (by "doing something" with server or maybe with AllowTerminate:=false; like above)

 

-terminate session on Connection down to clean temporary files

 

-to put "false" CloseApp button, and on click not to terminate,  and real termination will be on closing browser tab

 

-to keep transactions in one event

 

Good advices for the beginners!!! Thank you!!!

Link to comment
Share on other sites

Well, there was a time when I really wanted documentation - I can easily admit that.

 

When I started using Unigui and looked at the examples, and found not a single piece of code that did anything,

I was really scratching my head, wondering what was happening.

 

At that time I thought to myself, "How come Farshad could not write just a single line to tell where the magic was happening?"

 

Of course the code was there, buried within the Ext events for example....because the example was definitely working.

 

But I did not have to search a lot to find this - after all there is not an unlimited number of places to search !

 

My point is that if you then spend 5 minutes searching and swearing, and eventually find the code, 

you will not easily forget how this was done.

 

I would not really call this a steep learning curve. Tell me which other web dev system you can learn in

a couple of weeks, a few hours each day, and which is so easy to master once you get the hang of it.

 

Bottom line is that the need for documentation when using Unigui is not even close to the need of

other systems, and that is why - that is why - Unigui has gained such popularity even with practically

no documentation. Beat that!

 

Of course the forum has been critical in this process, and if I should choose, I would go for the forum

instead of the doc's, because you get the social support of seeing many others using it, and that is sweet. :)

  • Upvote 2
Link to comment
Share on other sites

Completely agree!!! 5 minutes, and some times 5 days for finding decision and you will never forget how did you do this. But nevertheless I post such "findings"  to my blog - because after year sometimes it is faster to take a look on couple of strings that can help you! And also they can help to someone else! :biggrin:

 

So, I think this topic can be closed!!! The answer is received. Thank you everyone for discussion!!! 

 

 

Link to comment
Share on other sites

Completely agree!!! 5 minutes, and some times 5 days for finding decision and you will never forget how did you do this. But nevertheless I post such "findings"  to my blog - because after year sometimes it is faster to take a look on couple of strings that can help you! And also they can help to someone else! :biggrin:

 

So, I think this topic can be closed!!! The answer is received. Thank you everyone for discussion!!! 

 

 

 

post-2378-0-98059700-1455883540_thumb.jpg

  • Upvote 1
Link to comment
Share on other sites

I agree with Oscar, I think the session model build from first to match the desktop systems, specially when UniGui has double compile for desktop/web for same application.

 

elGringo, I think you should little differently with web users, if user open his application and didn't use it for hours, why he should allocate session on the server?

 

in most web languages they have default session time for less than 30 min (asp.net 20Min, php 24 Min), I would think between 30 min and one hour is very reasonable time, otherwise if users never touch the application for longer than that time, his/her session should be terminated and this resources should be allocated for another users.

 

also each session it allocate around 10MB as session on server, so if you have 100 active session * 10 = 1GB of server RAM, beside the allocated cache folder for each session.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...