🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.internet.socket
Article #4965

Re: Non AnsiString Incoming Buffering in Indy Servers

#4965
From: Colin B Maharaj
Date: Mon, 22 Nov 2004 19:05
65 lines
3458 bytes
Thanks Remy for the insight, I will do some tweaking and see how things go.

Thanks!




Remy Lebeau (TeamB) wrote:
> "Colin B Maharaj" <noreply@myhost.com> wrote in message
> news:41a1c4cf$1@newsgroups.borland.com...
> 
> 
>>   TIdTCPClient *WebSite = new TIdTCPClient(NULL);
> 
> 
> Why are you using TIdTCPClient directly and not TIdHTTP instead?
> 
> 
>>   WebSite->ReadStream(Stream, -1, true); // read from site to stream
> 
> 
> That will not work.  You are specifying 'true' for the AReadUntilDisconnect
> parameter, but the connection is not going to close in the first place due
> to the Keep-Alive.  You are not reading the data from the socket properly at
> all.  You should be doing what the HTTP protocol requires you to do -
> calling ReadLn() in a loop to read the response headers line by line until
> you find a blank line, and then read the remaining data based on what the
> headers indicate, such as by looking at the "Content-Length" header value to
> know how much additional data you need to read.
> 
> 
>>   AThread->Connection->Disconnect();
> 
> 
> Since you are disconnecting the browser, your TIdPeerThread will be
> terminated, and you will lose your connection to the web site anyway.
> First, you should be checking if the browser is also requesting a Keep-Alive
> of its own.  If so, then don't terminate the browser connection at all and
> include a "Connection: Keep-Alive" header in your response to the browser,
> and don't terminate the TIdPeerThread at all.  If not requested by the
> browser, on the other hand, then the only way to maintain a persistent
> connection to the web site while still being able to terminate the browser
> connection is to move the web site connection to a separate thread of its
> own altogether.
> 
> 
>>How can I get incoming data from a TCP Connection that does not
>>go to an AnsiString but to a buffer of sorts, that may contain null
>>characters in between (e.g. jpeg image).
> 
> 
> You already know how, because you are already doing it.  You just need to
> tweak that code to handle the headers properly first.
> 
> 
>>Also this routing must be able to 'timeout' as it were since some
>>connection may not drop cause of the keep alive scenario
> 
> 
> That is what the TIdTCPConnection.ReadTimeout property is for.
> 
> 
> Gambit
> 
> 
Technical Details
Message-ID: <41a2388c$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!proxad.net!213.200.89.82.MISMATCH!tiscali!newsfeed1.ip.tiscali.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <41a1c4cf$1@newsgroups.borland.com> <41a22d10$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,9e62d9fb8e1bfe4a
X-Google-Attributes: gid11508e,public
X-Google-Language: ENGLISH,ASCII-7-bit
Date: Mon, 22 Nov 2004 15:05:53 -0400
From: Colin B Maharaj <noreply@myhost.com>
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7a) Gecko/20040219
X-Accept-Language: en-us, en
MIME-Version: 1.0
Newsgroups: borland.public.cppbuilder.internet.socket
Subject: Re: Non AnsiString Incoming Buffering in Indy Servers
References: <41a1c4cf$1@newsgroups.borland.com> <41a22d10$1@newsgroups.borland.com>
In-Reply-To: <41a22d10$1@newsgroups.borland.com>
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 200.108.15.43
Message-ID: <41a2388c$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1101150348 200.108.15.43 (22 Nov 2004 11:05:48 -0700)
Lines: 65
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!proxad.net!213.200.89.82.MISMATCH!tiscali!newsfeed1.ip.tiscali.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail