🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Threaded Client Application

#3542
From: Curt
Date: Wed, 24 Aug 2005 02:28
78 lines
3676 bytes
Thank you very much Gambit.  Your comments are right on.  I programmed my
app according to your directions and it works well!






"Remy Lebeau (TeamB)" <no.spam@no.spam.com> wrote in message
news:430a0326$1@newsgroups.borland.com...
>
> "Curt" <noemailaddress> wrote in message
> news:43091119$1@newsgroups.borland.com...
>
> > In Form1->OnCreate()
>
> Do not use the OnCreate event in C++.  It is a Delphi remnant that
produces
> illegal behavior in C++ because it can be triggered before the
constructor.
>
> > I instantiate the TIdThread by calling TIdThread * ClientThread = new
> TIdThread();
>
> That will not work.  Like TThread, TIdThread is a base class that you need
> to derive a new class from in order to write the code that the thread will
> actually run.  TIdThread by itself does not do anything.  In fact,
TIdThread
> is an abstract class, so you cannot instantiate it directly anyway.
>
> > Then, within ClientThread, how should I use BeforeExecute, BeforeRun,
> > AfterRun, AfterExecute ?  Where should I put the Connect() and
> > Disconnect()
>
> Use BeforeRun() to Connect() and AfterRun() to Disconnect().  Use Run() to
> read a packet of data.
>
> > where should I check to make sure that the connection has not been
broken?
>
> Put an try..catch block inside of Run().  If the connection is broken,
> reading from the client socket will thrown an exception.  As long as an
> exception does not escape from Run(), the thread will continue running.
>
> > how do I break out of the Run() loop without terminating the thread ?
>
> The only way is to call the thread's Stop() method.  There is a StopMode
> property that tells the thread what to do when stopped.  If set to
> smTerminate, the thread terminates itself.  If set to smSuspend, the
thread
> suspends itself.
>
> In the latter case, you would have to Start() the thread again at a later
> time from another thread, including when shutting the thread down for
good.
> On the other hand, if you don't want the thread to suspend itself, just to
> go back to BeforeRun() and start over, then you can override the
DoStopped()
> method (or use the OnStopped event) to call the thread's Start() method.
> Then the thread will not suspend itself at all.
>
> > I also thought of connecting in BeforeRun and then spawning an
> > additional thread in Run()
>
> You do not need another thread.  You are already in a thread.
>
> > 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.
>
> You do not need to do that.
>
>
> Gambit
>
>
Technical Details
Message-ID: <430bda94$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!mpls-transit-01.news.qwest.net!38.119.100.82.MISMATCH!news-out.newsgroups.com!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail
References: <43091119$1@newsgroups.borland.com> <430a0326$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,41952c36e9beb1f7
X-Google-Attributes: gid11508e,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Curt" <noemailaddress>
Newsgroups: borland.public.cppbuilder.internet.socket
References: <43091119$1@newsgroups.borland.com> <430a0326$1@newsgroups.borland.com>
Subject: Re: Threaded Client Application
Date: Tue, 23 Aug 2005 21:28:16 -0500
Lines: 80
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: 67.37.235.30
Message-ID: <430bda94$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1124850324 67.37.235.30 (23 Aug 2005 19:25:24 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!mpls-transit-01.news.qwest.net!38.119.100.82.MISMATCH!news-out.newsgroups.com!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail