🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Threaded Client Application

#3536
From: Curt
Date: Sun, 21 Aug 2005 23:43
36 lines
2156 bytes
Hi,

    I have a very basic client application which needs a threaded client
which will :

1- connect to a proprietary server
2- login
3- receive streaming data continually and store it in a flat file.
4- if a disconnect should occur for any reason the client should try to
reconnect


My question is, what is the best way to implement this behaviour ?

I am creating a threaded client using TIdThread and TIdTCPClient.

In Form1->OnCreate() I instantiate the TIdThread by calling TIdThread *
ClientThread = new TIdThread();

Then, within ClientThread, how should I use BeforeExecute, BeforeRun,
AfterRun, AfterExecute ?  Where should I put the Connect() and Disconnect()
and where should I check to make sure that the connection has not been
broken?

Is it Connect() in BeforeExecute and Disconnect() in AfterExecute ?  If so,
how do I break out of the Run() loop without terminating the thread ?

I also thought of connecting in BeforeRun and then spawning an additional
thread in Run() which would do the work of reading the Connection and then
terminate itself when a disconnect takes place returning control to the
original thread which would reestablish the connection.

Please forgive the barrage of questions.

Thanks,
Curt
Technical Details
Message-ID: <43091119$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!fr.ip.ndsoftware.net!feeder.enertel.nl!nntpfeed-01.ops.asmr-01.energis-idc.net!news-out.nntp.be!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,41952c36e9beb1f7,start
X-Google-Attributes: gid11508e,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Curt" <noemailaddress>
Newsgroups: borland.public.cppbuilder.internet.socket
Subject: Threaded Client Application
Date: Sun, 21 Aug 2005 18:43:57 -0500
Lines: 42
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1506
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1506
NNTP-Posting-Host: 65.43.116.207
Message-ID: <43091119$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1124667673 65.43.116.207 (21 Aug 2005 16:41:13 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!fr.ip.ndsoftware.net!feeder.enertel.nl!nntpfeed-01.ops.asmr-01.energis-idc.net!news-out.nntp.be!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail