🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

TIdPeerThread / IdTCPServer1 Multi Treaded problems

#4120
From: Andy Blackmore
Date: Fri, 08 Apr 2005 11:23
39 lines
1974 bytes
Hello
  I am trying to create a multi threaded server with a local variable to 
each thread and not a global one. I first tried the code listed below :-

void __fastcall TFArt::IdTCPServer1Execute(TIdPeerThread *AThread)
{
 static int Count = 0;
 AnsiString ReplyStr;

 ReplyStr = AThread->Connection->ReadLn();

 if(ReplyStr == "c")
   {
    Count++;
    AThread->Connection->WriteLn("Count = " + IntToStr(Count));
   }
 else
   if(ReplyStr == 'q')
     AThread->Connection->Disconnect();
}

But I found that the variable listed here (Count) is global to all threads. 
So I looked at creating a new class derived from TIdPeerThread and called 
TMyIdThread where I can declair a local variable

class TMyIdThread : public  TIdPeerThread {
public:
    int Count;
protected:
private:
];

But I don't know how I link this new class into the IdTCPServer component. 
Please can someone help me with this problem

Thanks in advance


Andy Blackmore 
Technical Details
Message-ID: <425669ba@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!newshosting.com!nx01.iad01.newshosting.com!news-peer0-test!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,3ba22e438513e68b,start
X-Google-Attributes: gid11508e,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Andy Blackmore" <andy@number18.co.uk>
Newsgroups: borland.public.cppbuilder.internet.socket
Subject: TIdPeerThread / IdTCPServer1 Multi Treaded problems
Date: Fri, 8 Apr 2005 12:23:38 +0100
Lines: 41
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
X-RFC2646: Format=Flowed; Original
NNTP-Posting-Host: 193.195.12.161
Message-ID: <425669ba@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1112959418 193.195.12.161 (8 Apr 2005 04:23:38 -0800)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!newshosting.com!nx01.iad01.newshosting.com!news-peer0-test!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mail