Re: What is this code waiting for?
From: FISH (joeking_at_merseymail.com)
Date: 03/11/04
- Next message: Boniface Frederic: "byte conversion"
- Previous message: FISH: "Re: simple i think"
- In reply to: Princess Morgiah: "What is this code waiting for?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 11 Mar 2004 03:48:22 -0800
"Princess Morgiah" <princess_morgiah_nospamplease@yahoo.com> wrote in message news:<iRL3c.30224$UA7.2104432@phobos.telenet-ops.be>...
> Hi everyone,
>
> I just finished a small test program which is supposed to retrieve a file
> from a webserver using sockets.
>
> The code works fine and retrieves the file as expected, but waits for a very
> long time after the file has been received. After the last byte of the file
> (about 300k) is accepted, the program stalls for about 15 seconds, which is
> compared to a browser 15 seconds too long :)
>
> I suspected to see this code continue without interruption after downloading
> the file, and I cannot see what's going wrong here.
[Code snipped...]
Scanning through the code the most glaring problem is the use of HTTP/1.1
and Keep-Alive in the outgoing headers. I'll wager that the incoming
header contains a confirmation that the connection will be kept open for
further requests. Your loop reading the data is sat waiting for more
data, and the web server is sat waiting for another request. Eventually
the server times out the connection - and your read method returns
gracefully by indicating there is no further data to get.
When using HTTP/1.1, both sides assume that the connection will be kept
open by default for further requests. The way that one side or t'other
indicates that the connection is to be closed is to set Connection to
"close", not "keep-alive". If you send that header then the server
will know that this is the last request (only request?) on that socket
connection. If the server sets that header, your client must expect
that the server will terminate the connection once the current response
is received - even if your client asked for keep-alive!
Note: this is the opposite defaults to HTTP v1.0, where the connection
is always closed unless the client requests it stay open. (I'm not
sure if keep-alive was ever an official part of 1.0 (?)... but I think
most servers do support it!)
-FISH- ><>
- Next message: Boniface Frederic: "byte conversion"
- Previous message: FISH: "Re: simple i think"
- In reply to: Princess Morgiah: "What is this code waiting for?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|