Why not Request.IsClientConnected?

Hi Experts,

I have seen following code in a few tutorials
If response.IsClientConnected=true then
but there is not good explanation for that and I got questions:
1. What does disconnected mean?
2. Is a client a session?
3. If we got a few client, when we know response.IsClientConnected = true, how to know which session/client is connected?
4. Why not Request.IsClientConnected?
daveaskAsked:
Who is Participating?
 
joeposter649Commented:
I think huji covered a lot here but you should realize that, just like the rest of the response methods, IsClientConnected can only be used once the browser requests a page.  Nothing in asp can initiate contact with the client.

This link might help too.
http://devguru.com/Technologies/asp/quickref/response_isclientconnect.html
0
 
hujiCommented:
As far as I know, there are some cases in which the client is disconnected (for example by closing the browser window) but the server does not sense it. That is, the server continues processing the codes which takes resources and time. So for huge processings you can ensure the client to be still connected by that piece of code, and stop the rest of the code, if he is disconnected.
An example is, you can put some lines in golbal.asa file under Session_OnEnd function, and hope that they are run when the client disconnects from your site, any way, but in reality, this may be done only sometimes.

Wish I can help
Huji
0
 
daveaskAuthor Commented:
Thank you.
So,
1. the server cannot accurately know when the client disconnects,
2. the server can delect if a client still disconnected or not by send something to the client, that is why it uses response instead of request,
3. put response.IsClientConnected in Session_OnEnd function so that after a session timeout interval we know this session(client) is really disconnected or not,
4. it is no use to put response.IsClientConnected in another places (other than Session_OnEnd or Session_OnStart), because we wont know which client we are checking.

Am I right?
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
hujiCommented:
Part 1 and 2 are correct.
Part 3 is not. Session_OnEnd is run when the server knows that the client is disconnected, so untill it does not know that, it will not run that function, and IsClientConnected is not called.
Part 4 is not correct again. You can use IsClientConnected in many other places, and I give you an example:
When a user makes arequest which needs lots of processing and connecting to several databases (which may take as much as 20 seconds on your server for example), you can check if he is still connected, in the middle of the processing code; if not, you can simply cancel the rest of the processing to free some CPU for other online users.
Wish I can help
Huji
0
 
daveaskAuthor Commented:
Thank you and I am glad that I got two of four are correct :)

>Session_OnEnd is run when the server knows that the client is disconnected
It seems to me that Session_OnEnd is fired when timeout instead when the client closes his browser!

>You can use IsClientConnected in many other places
If we have a few clients, when we find response.IsClientConnected = False, how to know which client disconnected?
0
 
hujiCommented:
No. The session is ended when it is ENDED any ways! You specify session timeout as 30 minutes, and it means that if the user has his window open and remains idle (no clicks, no other types of reconnection to your server) then the session is ended after 30 minutes, but if the user refreshes the page 29 miinutes 55 seconds after the last connection to your site, the session is renewed again, and another 30 minutes will be needed for OnEnd to happen.
Passing the timout is only one way to finish sessions. Another situation is when the server understands that the user has closed the browser window related to that session number, but this is not detected by servers as often as it happens.
Second and more iportant point: when Reponse.IsClientConnected is Flase, it means that THIS session is disconnected! and the ID of this session variable is stored in Session.SessionID (read-only) property. You can not know which username in your database is disconnected, unless you store the sessionID when the user is authenticated in the database.
Don't hesitate to ask questions.
Wish I can help
Huji
0
 
hujiCommented:
Well joeposter649 noted a good point. As IsClientConnected is a reposnse method, it can only be called when a RESPONSE is being made. So you can call it several times after a response STARTs and before it is ENDed.
I suppose that your question is answered, am I right daveask?

Wish I can help
Huji
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.