🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Non AnsiString Incoming Buffering in Indy Servers

#4964
From: Remy Lebeau (TeamB)
Date: Mon, 22 Nov 2004 18:18
46 lines
3135 bytes
"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: <41a22d10$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!proxad.net!fr.ip.ndsoftware.net!border2.nntp.ams.giganews.com!border1.nntp.ams.giganews.com!nntp.giganews.com!pe2.news.blueyonder.co.uk!blueyonder!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mail
References: <41a1c4cf$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
From: "Remy Lebeau \(TeamB\)" <no.spam@no.spam.com>
Newsgroups: borland.public.cppbuilder.internet.socket
References: <41a1c4cf$1@newsgroups.borland.com>
Subject: Re: Non AnsiString Incoming Buffering in Indy Servers
Date: Mon, 22 Nov 2004 10:18:50 -0800
Lines: 48
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1409
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409
NNTP-Posting-Host: 68.69.17.41
Message-ID: <41a22d10$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1101147408 68.69.17.41 (22 Nov 2004 10:16:48 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!proxad.net!fr.ip.ndsoftware.net!border2.nntp.ams.giganews.com!border1.nntp.ams.giganews.com!nntp.giganews.com!pe2.news.blueyonder.co.uk!blueyonder!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mail