Article View: borland.public.cppbuilder.internet.socket
Article #2675Re: Multi-threaded TCP Server with Indy 9
From: Martin
Date: Sat, 11 Mar 2006 13:50
Date: Sat, 11 Mar 2006 13:50
56 lines
2841 bytes
2841 bytes
OK, this is my (working) code i am currently using:
//---------------------------------------------------------------------------
class TMyThreadClass
{
public:
TIdPeerThread* pAThread;
int someparameter;
void __fastcall Process();
protected:
private:
};
//---------------------------------------------------------------------------
void __fastcall TForm1::IdTCPServer1Connect(TIdPeerThread *AThread)
{
TMyThreadClass* pMyThreadClass;
pMyThreadClass= new TMyThreadClass();
pMyThreadClass->someparameter=1; // initializing parameters
AThread->Data = (TObject*) pMyThreadClass;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::IdTCPServer1Disconnect(TIdPeerThread *AThread)
{
TMyThreadClass* pMyThreadClass;
pMyThreadClass = (TMyThreadClass*) AThread->Data;
delete pMyThreadClasss;
AThread->Data = NULL;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::IdTCPServer1Execute(TIdPeerThread *AThread)
{
TMyThreadClass* pMyThreadClass;
pMyThreadClass = (TMyThreadClass*) AThread->Data;
pMyThreadClass->pAThread = (TIdPeerThread*) AThread;
// read from with AThread->Connection->CurrentReadBuffer()
if (...) // some conditions
{
Process();
}
}
//---------------------------------------------------------------------------
void __fastcall TDeviceClass::Process()
{
// Example
pAThread->Connection->WriteLn("Hello!");
}
//---------------------------------------------------------------------------
This code works fine. But i want to assign MyThreadClass to
IdTCPServer->ThreadClass.
You wrote in a previous thread, that this would be the better solution.
But i gave it up due some access violations.
Regards, Martin
Technical Details
Message-ID:
<4412d582@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news3.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-mailReferences:
<441145d6$1@newsgroups.borland.com> <4411c95f$3@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,77f2a3a304e17124 X-Google-Attributes: gid11508e,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Martin" <martin@styleworx.com> Newsgroups: borland.public.cppbuilder.internet.socket References: <441145d6$1@newsgroups.borland.com> <4411c95f$3@newsgroups.borland.com> Subject: Re: Multi-threaded TCP Server with Indy 9 Date: Sat, 11 Mar 2006 14:50:44 +0100 Lines: 59 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.2670 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670 X-RFC2646: Format=Flowed; Original NNTP-Posting-Host: 81.189.109.34 Message-ID: <4412d582@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1142084994 81.189.109.34 (11 Mar 2006 05:49:54 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news3.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