473,322 Members | 1,232 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

How to check in CGI if client disconnected

Hi,

I am writing a CGI to serve files to the caller. I was wondering if
there is any way to tell in my CGI if the client browser is still
connected. If it is not, i want to execute some special code before
exiting.

Is there any way to do this? Any help on this is appreciated :)

Regards,

-vishal.
Aug 24 '08 #1
7 2551
En Sun, 24 Aug 2008 14:25:03 -0300, Vishal <vr****@gmail.comescribió:
I am writing a CGI to serve files to the caller. I was wondering if
there is any way to tell in my CGI if the client browser is still
connected. If it is not, i want to execute some special code before
exiting.

Is there any way to do this? Any help on this is appreciated :)
I don't think so. A CGI script runs once per request, and exits. The server may find that client disconnected, but that may happen after the script finished.

--
Gabriel Genellina

Aug 24 '08 #2
On Sun, 24 Aug 2008 17:21:52 -0300, Gabriel Genellina wrote:
> I am writing a CGI to serve files to the caller. I was wondering if
there is any way to tell in my CGI if the client browser is still
connected. If it is not, i want to execute some special code before
exiting.

Is there any way to do this? Any help on this is appreciated :)

I don't think so. A CGI script runs once per request, and exits. The server may find that client disconnected, but that may happen after the script finished.
I am not a web developer, but I think that the only way is to
set a timeout on server side. You can't be sure that the client
disconnected, but you can stop CGI script if there's no
action on client side for too long.

--
Regards,
Wojtek Walczak,
http://tosh.pl/gminick/
Aug 24 '08 #3
En Sun, 24 Aug 2008 17:51:36 -0300, Wojtek Walczak <gm*****@bzt.bztescribió:
On Sun, 24 Aug 2008 17:21:52 -0300, Gabriel Genellina wrote:
>> I am writing a CGI to serve files to the caller. I was wondering if
there is any way to tell in my CGI if the client browser is still
connected. If it is not, i want to execute some special code before
exiting.

Is there any way to do this? Any help on this is appreciated :)

I don't think so. A CGI script runs once per request, and exits. The server may find that client disconnected, but that may happen after the script finished.

I am not a web developer, but I think that the only way is to
set a timeout on server side. You can't be sure that the client
disconnected, but you can stop CGI script if there's no
action on client side for too long.
Which kind of client action? Every link clicked or form submitted generates a different request that triggers a CGI script; the script starts, reads its parameters, do its task, and exits. There is no "long running process" in CGI - the whole "world" must be recreated on each request (a total waste of resources, sure).

If processing takes so much time, it's better to assign it a "ticket" - the user may come back later and see if its "ticket" has been finished, or the system may send an email telling him.

--
Gabriel Genellina

Aug 24 '08 #4
Hi,

Thanks for the replies. In my case, the cgi is sending a large file
to the client. In case the the stop button is pressed on the browser
to cancel the download, i want to do some cleanup action. It's all one-
way transfer in this case, so i can't expect the client to send
anything to me. I read somewhere that apache sends the SIGTERM signal
to a cgi when the client disconnects. However, my cgi is not getting
the signal - is there a way to have the cgi catch and handle the
SIGTERM?

I tried using the signal module

---
def sigtermHandler(signum, frame):
# do some cleanup

signal.signal(signal.SIGTERM, sigtermHandler)

---

But even this doesn't work.

Regards,

-vishal.
On Aug 25, 2:58*am, "Gabriel Genellina" <gagsl-...@yahoo.com.ar>
wrote:
En Sun, 24 Aug 2008 17:51:36 -0300, Wojtek Walczak <gmin...@bzt.bztescribió:
On Sun, 24 Aug 2008 17:21:52 -0300, Gabriel Genellina wrote:
>* *I am writing a CGI to serve files to the caller. I was wondering if
there is any way to tell in my CGI if the client browser is still
connected. If it is not, i want to execute some special code before
exiting.
>* *Is there any way to do this? Any help on this is appreciated :)
I don't think so. A CGI script runs once per request, and exits. The server may find that client disconnected, but that may happen after the script finished.
I am not a web developer, but I think that the only way is to
set a timeout on server side. You can't be sure that the client
disconnected, but you can stop CGI script if there's no
action on client side for too long.

Which kind of client action? Every link clicked or form submitted generates a different request that triggers a CGI script; the script starts, readsits parameters, do its task, and exits. There is no "long running process"in CGI - the whole "world" must be recreated on each request (a total waste of resources, sure).

If processing takes so much time, it's better to assign it a "ticket" - the user may come back later and see if its "ticket" has been finished, or the system may send an email telling him.

--
Gabriel Genellina
Aug 25 '08 #5
On Aug 25, 4:26*pm, Vishal <vrs...@gmail.comwrote:
Hi,

* Thanks for the replies. In my case, the cgi is sending a large file
to the client. In case the the stop button is pressed on the browser
to cancel the download, i want to do some cleanup action. It's all one-
way transfer in this case, so i can't expect the client to send
anything to me. I read somewhere that apache sends the SIGTERM signal
to a cgi when the client disconnects. However, my cgi is not getting
the signal - is there a way to have the cgi catch and handle the
SIGTERM?

I tried using the signal module

---
def sigtermHandler(signum, frame):
* * # do some cleanup

signal.signal(signal.SIGTERM, sigtermHandler)

---

But even this doesn't work.
Have you considered simply checking to see if the amount of POST
content read matches the inbound Content-Length specified in the CGI
environment. If your processing of POST content finds less than what
was meant to be sent, then likely that the client browser aborted
request before all content could be sent.

Graham
Regards,

-vishal.
On Aug 25, 2:58*am, "Gabriel Genellina" <gagsl-...@yahoo.com.ar>
wrote:
En Sun, 24 Aug 2008 17:51:36 -0300, Wojtek Walczak <gmin...@bzt.bztescribió:
On Sun, 24 Aug 2008 17:21:52 -0300, Gabriel Genellina wrote:
>>* *I am writing a CGI to serve files to the caller. I was wondering if
>>there is any way to tell in my CGI if the client browser is still
>>connected. If it is not, i want to execute some special code before
>>exiting.
>>* *Is there any way to do this? Any help on this is appreciated:)
>I don't think so. A CGI script runs once per request, and exits. Theserver may find that client disconnected, but that may happen after the script finished.
I am not a web developer, but I think that the only way is to
set a timeout on server side. You can't be sure that the client
disconnected, but you can stop CGI script if there's no
action on client side for too long.
Which kind of client action? Every link clicked or form submitted generates a different request that triggers a CGI script; the script starts, reads its parameters, do its task, and exits. There is no "long running process" in CGI - the whole "world" must be recreated on each request (a total waste of resources, sure).
If processing takes so much time, it's better to assign it a "ticket" -the user may come back later and see if its "ticket" has been finished, orthe system may send an email telling him.
--
Gabriel Genellina
Aug 25 '08 #6
Hi Graham,

Thanks for the reply. In my case, it's the other way round. I need
to check if the amount of data sent is equal to the file size i want
to send. However, the question is - when do i check this? Currently, i
am unable to call any cleanup code before exit.

Regards,

-vishal.

On Aug 25, 11:44*am, Graham Dumpleton <Graham.Dumple...@gmail.com>
wrote:
On Aug 25, 4:26*pm, Vishal <vrs...@gmail.comwrote:
Hi,
* Thanks for the replies. In my case, the cgi is sending a large file
to the client. In case the the stop button is pressed on the browser
to cancel the download, i want to do some cleanup action. It's all one-
way transfer in this case, so i can't expect the client to send
anything to me. I read somewhere that apache sends the SIGTERM signal
to a cgi when the client disconnects. However, my cgi is not getting
the signal - is there a way to have the cgi catch and handle the
SIGTERM?
I tried using the signal module
---
def sigtermHandler(signum, frame):
* * # do some cleanup
signal.signal(signal.SIGTERM, sigtermHandler)
---
But even this doesn't work.

Have you considered simply checking to see if the amount of POST
content read matches the inbound Content-Length specified in the CGI
environment. If your processing of POST content finds less than what
was meant to be sent, then likely that the client browser aborted
request before all content could be sent.

Graham
Regards,
-vishal.
On Aug 25, 2:58*am, "Gabriel Genellina" <gagsl-...@yahoo.com.ar>
wrote:
En Sun, 24 Aug 2008 17:51:36 -0300, Wojtek Walczak <gmin...@bzt.bztescribió:
On Sun, 24 Aug 2008 17:21:52 -0300, Gabriel Genellina wrote:
>* *I am writing a CGI to serve files to the caller. I was wondering if
>there is any way to tell in my CGI if the client browser is still
>connected. If it is not, i want to execute some special code before
>exiting.
>* *Is there any way to do this? Any help on this is appreciated :)
I don't think so. A CGI script runs once per request, and exits. The server may find that client disconnected, but that may happen after the script finished.
I am not a web developer, but I think that the only way is to
set a timeout on server side. You can't be sure that the client
disconnected, but you can stop CGI script if there's no
action on client side for too long.
Which kind of client action? Every link clicked or form submitted generates a different request that triggers a CGI script; the script starts, reads its parameters, do its task, and exits. There is no "long running process" in CGI - the whole "world" must be recreated on each request (a total waste of resources, sure).
If processing takes so much time, it's better to assign it a "ticket"- the user may come back later and see if its "ticket" has been finished, or the system may send an email telling him.
--
Gabriel Genellina

Aug 25 '08 #7
On Aug 25, 5:49*pm, Vishal <vrs...@gmail.comwrote:
Hi Graham,

* *Thanks for the reply. In my case, it's the other way round. I need
to check if the amount of data sent is equal to the file size i want
to send. However, the question is - when do i check this? Currently, i
am unable to call any cleanup code before exit.
Best you will do for writing, is to catch exceptions around the call
outputing the data. If an exception occurs then a problem has
obviously occurred.

Graham
Regards,

-vishal.

On Aug 25, 11:44*am, Graham Dumpleton <Graham.Dumple...@gmail.com>
wrote:
On Aug 25, 4:26*pm, Vishal <vrs...@gmail.comwrote:
Hi,
* Thanks for the replies. In my case, the cgi is sending a large file
to the client. In case the the stop button is pressed on the browser
to cancel the download, i want to do some cleanup action. It's all one-
way transfer in this case, so i can't expect the client to send
anything to me. I read somewhere that apache sends the SIGTERM signal
to a cgi when the client disconnects. However, my cgi is not getting
the signal - is there a way to have the cgi catch and handle the
SIGTERM?
I tried using the signal module
---
def sigtermHandler(signum, frame):
* * # do some cleanup
signal.signal(signal.SIGTERM, sigtermHandler)
---
But even this doesn't work.
Have you considered simply checking to see if the amount of POST
content read matches the inbound Content-Length specified in the CGI
environment. If your processing of POST content finds less than what
was meant to be sent, then likely that the client browser aborted
request before all content could be sent.
Graham
Regards,
-vishal.
On Aug 25, 2:58*am, "Gabriel Genellina" <gagsl-...@yahoo.com.ar>
wrote:
En Sun, 24 Aug 2008 17:51:36 -0300, Wojtek Walczak <gmin...@bzt.bztescribió:
On Sun, 24 Aug 2008 17:21:52 -0300, Gabriel Genellina wrote:
>>* *I am writing a CGI to serve files to the caller. I was wondering if
>>there is any way to tell in my CGI if the client browser is still
>>connected. If it is not, i want to execute some special code before
>>exiting.
>>* *Is there any way to do this? Any help on this is appreciated :)
>I don't think so. A CGI script runs once per request, and exits.The server may find that client disconnected, but that may happen after the script finished.
I am not a web developer, but I think that the only way is to
set a timeout on server side. You can't be sure that the client
disconnected, but you can stop CGI script if there's no
action on client side for too long.
Which kind of client action? Every link clicked or form submitted generates a different request that triggers a CGI script; the script starts,reads its parameters, do its task, and exits. There is no "long running process" in CGI - the whole "world" must be recreated on each request (a total waste of resources, sure).
If processing takes so much time, it's better to assign it a "ticket" - the user may come back later and see if its "ticket" has been finished, or the system may send an email telling him.
--
Gabriel Genellina
Aug 25 '08 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Craig G | last post by:
is there a way to distinguish whether a client is using IE or Netscape? is there some sorta check i can run on the Page_Load event? or where would be the best place to do this? Cheers, Craig
1
by: Mike Dole | last post by:
I'm sorry to bother you with this question but it was either this or giving up and trying to go for a simpler solution (which I will if this is not gonna work out..) I'm afraid this is way out...
0
by: Jeremy Chapman | last post by:
Our web apps automatically log exceptions in the event log. We monitor this and I've noticed an exception being thrown throughout the day. The message is "The client disconnected.". I have been...
0
by: Ganwold | last post by:
I have a created a multi-threaded TcpClient server that works for my needs. Each thread uses synchronous (blocked) communication to wait for a command from the client Here's the problem...if a...
4
by: =?Utf-8?B?SGl3ag==?= | last post by:
I recently upgraded my application from VB6, and was using the Winsock control. In VB2005 I am using the TcpListener Class and have managed to get it working, except for one thing: Is there a...
1
by: Prakash Vaghela | last post by:
Hi all, We are using a data-service in our project that gets appropriate data from database and stores it into local cache (datasets, datatables). When we need to write modified data back to...
3
by: jlgeris | last post by:
I have a fairly simple client/server structure using System.Net.Sockets, where the server only sends data to a collection of clients, and the clients only receive data, so, the data flow is...
3
by: yogarajan | last post by:
hi All i would like to check client machine script property if client machine scripting -> active script is disable means i want rise one alert message how can i check the client machine...
5
by: NewLegend | last post by:
Hello i'm writing a class for network all works fine but when client disconnected my code can't dected it so if u can help me or say is there an error on the code i will be glad ,alot of thanks ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.