Re: What is this code waiting for?

From: FISH (joeking_at_merseymail.com)
Date: 03/11/04


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- ><>



Relevant Pages

  • Re: minimal httpd response
    ... RST, abortively closing the connection. ... The responsibilities of an HTTP/1.1 proxy, and of an HTTP/1.1 server ... user agent, without a proxy, first, and then try to deal ... Connection header; with a Content-length header; or with the chunked ...
    (comp.programming)
  • Re: Slow DNS requests?
    ... I think that the delay is in resolving the DNS requests. ... Guest machines connected via CAT5 to the BEFSR41 run fine. ... As soon as the host name is resolved, performance seems to improve dramatically for that connection. ... your DHCP server will tell your machine what name servers to use. ...
    (comp.os.linux.networking)
  • HTTP DDoS attack on our servers
    ... which appears like a DDoS attack. ... The requests always look the same way: ... Even though the server which ran at 8000 could not ... handle HTTP requests at all and immediately closed the connection after the ...
    (Incidents)
  • Re: downloading a single file using multiple threads
    ... The multi part requests in HTTP1.1 are meant to request a single part or multiple parts in a single request, but you can't requests multiple parts in parallel from multiple client threads. ... I know that down-load managers claim to work over HTTP, but that doesn't mean they support multi-part parallel request handling over the same or multiple connections, I don't even know if the protocol allows you to issue new range request when you have a range requests pending. ... If on one connection the client asks for the first megabyte and on a second connection the same client asks for the second megabyte, then if the server is capable of servicing both requests at the same time, there's no reason the client can't wind up receiving both the first and second megabytes in parallel. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Problem with a Socket server program opening/accepting many connections and the GC is running.
    ... I'm not quite sure what you mean by "slowed down my server by adding a 10ms ... to handle the connection as quickly as possible? ... other clients requests are being serviced. ... >> available sockets. ...
    (microsoft.public.dotnet.framework.performance)