🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Using TClientSocket in multi-threaded app

#2413
From: SF
Date: Wed, 26 Apr 2006 09:59
48 lines
2475 bytes
> TClientSocket *sock = new TClientSocket(MainForm);

I always use

TClientSocket *sock = new TClientSocket(NULL);

to create client sockets inside a thread. You yourself noticed 
this is the right way.

> My theory as to why I would get AVs is that maybe all three 
> threads are calling new TClientSocket(MainForm) almost 
> simultaneously and basically,

I don't care about that. Why should MainForm be the owner of an 
object created inside a different thread?

> The biggest hole in my theory that I can see is that it 
> doesn't really explain why it would work on my PC and not my 
> clients.

That should be deeply checked, but again, you shouldn't care too 
much IMO.

> It still could be a timing issue,

Or another thousands of issues...

> Also, the only advantage that I can see to having MainForm 
> being the owner of the TClientSocket is that if something 
> unexpected occurs and the TClientSocket doesn't get deleted 
> somehow, the MainForm will free up the memory when the form 
> gets destroyed.

Not a big advantage. Almost a disadvantage under certain points 
of view.

> This advantage is greatly decreased by the fact that the form 
> is never destroyed until the program exits, in which case 
> Windows is going to free up the memory anyway.

Anyway, your thread should be strong enough to handle any 
possible problem and free the TClientSocket pointer by itself.

Did you find anything more in the meantime?

HTH,

Stefano. 
Technical Details
Message-ID: <444f4499$2@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <4447ee51$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,f074aec44b23f651
X-Google-Attributes: gid11508e,public
X-Google-Language: ENGLISH,ASCII-7-bit
Reply-To: "SF" <invalid@NOSPAMinvalid.com>
From: "SF" <invalid@NOSPAMinvalid.com>
Newsgroups: borland.public.cppbuilder.internet.socket
References: <4447ee51$1@newsgroups.borland.com>
Subject: Re: Using TClientSocket in multi-threaded app
Date: Wed, 26 Apr 2006 11:59:42 +0200
Lines: 50
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.2869
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2869
X-RFC2646: Format=Flowed; Response
NNTP-Posting-Host: 81.208.124.114
Message-ID: <444f4499$2@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1146045593 81.208.124.114 (26 Apr 2006 02:59:53 -0700)
Path: arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail