Solved

Why not Request.IsClientConnected?

Posted on 2004-09-19
7
896 Views
Last Modified: 2011-10-03
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?
0
Comment
Question by:daveask
  • 4
  • 2
7 Comments
 
LVL 14

Assisted Solution

by:huji
huji earned 70 total points
Comment Utility
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
 

Author Comment

by:daveask
Comment Utility
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
 
LVL 14

Expert Comment

by:huji
Comment Utility
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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

Author Comment

by:daveask
Comment Utility
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
 
LVL 14

Expert Comment

by:huji
Comment Utility
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
 
LVL 15

Accepted Solution

by:
joeposter649 earned 30 total points
Comment Utility
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
 
LVL 14

Expert Comment

by:huji
Comment Utility
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

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now