HTTP::Daemon

L

Lars Oeschey

Hi,

I have a bit of a problem with the behaviour of HTTP::Daemon

my code looks like this:

------------------------------------------------------------
my $http = HTTP::Daemon->new ( LocalPort => 82);
print $http->url;
while (my $connect = $http->accept) {
$request=$connect->get_request;
if ($request->method eq "GET") {

$connect->send_response($html);
}
elsif ($request->method eq "POST") {

$connect->send_response($working);
&Action;
$connect->send_response($done);
}
}
$connect->close;
undef $connect;

sub Action {
print "Gruss von der Sub!\n";
sleep 20;
}
---------------------------------------------------------------

$html, $working and $done are html pages as string. $html displays a
button with method "post". The first page with the button gets
displayed fine, when I click on the button, there's a 20sec delay, and
then $working and $done get displayed at once. Is there a way to have
the delay actually happen between $working and $done? Is this some
buffering problem? Another Question: On every page I get a status line
displayed:
Date: Mon, 26 Jan 2004 21:30:25 GMT Server: libwww-perl-daemon/1.25

how can I switch that off?

Lars
 
B

Ben Morrow

Lars Oeschey said:
Hi,

I have a bit of a problem with the behaviour of HTTP::Daemon

$html, $working and $done are html pages as string. $html displays a
button with method "post". The first page with the button gets
displayed fine, when I click on the button, there's a 20sec delay, and
then $working and $done get displayed at once. Is there a way to have
the delay actually happen between $working and $done? Is this some
buffering problem?

The solution to this problem is called 'server push'. I don't know if
HTTP::Daemon implements this.

Ben
 
G

gnari

Lars Oeschey said:
Hi,

I have a bit of a problem with the behaviour of HTTP::Daemon

[snipped daemon that tries to sleep in the middle of the request]

you have to realize how HTTP works.

the browser sends a request, that is a specially formatted text
message, to a port on the server.
the server, in this case your script, reads the request, processes
it and send back on the still open connection, a response.
the response also has a special format
the browser now displays the response.

your sleep just delays the moment that the browser can display
the response.

as we are talking HTML here, maybe a <META http-equiv="refresh">
tag would do the trick for you?

... Another Question: On every page I get a status line
displayed:
Date: Mon, 26 Jan 2004 21:30:25 GMT Server: libwww-perl-daemon/1.25

here we come to the format of the response.
the response starts with a number of header lines separated from the
response body by an empty line. the Daemon tries to create a valid header
by inserting headerlines like Date: and Server: , but probably something
you do causes an empty line to be emitted before that.
the browser interprets these headers as part of the body.

hope this helps

gnari
 
L

Lars Oeschey

as we are talking HTML here, maybe a <META http-equiv="refresh">
tag would do the trick for you?

hm, I changed $working to:

$working="<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01
Transitional//EN'>
<html>
<head>
<title>Bremsenpr&uuml;fstand I/EF-53</title>
<META http-equiv='refresh'>
<meta http-equiv='Content-Type' content='text/html;
charset=iso-8859-1'>
</head>
<BODY bgcolor='#999999'>
<p align='center'><font size='+1' face='Verdana, Arial, Helvetica,
sans-serif'>Die Daten werden geholt...</font>
</p>
</BODY>
</html>";

didn't help though...
here we come to the format of the response.
the response starts with a number of header lines separated from the
response body by an empty line. the Daemon tries to create a valid header
by inserting headerlines like Date: and Server: , but probably something
you do causes an empty line to be emitted before that.
the browser interprets these headers as part of the body.

As you can see above, I don't use anything unusal, at least I don't
see it...

Lars
 
G

gnari

Lars Oeschey said:
hm, I changed $working to:

...
<META http-equiv='refresh'>

sorry, I assumed you would look up the syntax of the META:
<META http-equiv='refresh' content='20;URL='>

google is your friend, and much faster that these newsgroups.

gnari
 
J

Joe Smith

Lars said:
sub Action {
print "Gruss von der Sub!\n";
sleep 20;
}
---------------------------------------------------------------

$html, $working and $done are html pages as string. $html displays a
button with method "post". The first page with the button gets
displayed fine, when I click on the button, there's a 20sec delay, and
then $working and $done get displayed at once. Is there a way to have
the delay actually happen between $working and $done?

Yes. Change that to
print "Gruss von der Sub!<br>\n";
so that the browser will render the current paragraph.
-Joe
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,145
Messages
2,570,826
Members
47,371
Latest member
Brkaa

Latest Threads

Top