Newsgroups : Borland : borland.public.delphi.internet.winsock : 2006 Dec : Re: Multythreading TIdTcpClient on workstation OS
| Subject: | Re: Multythreading TIdTcpClient on workstation OS |
| Posted by: | "Dejan Petrovic" (dejanbng@removethis.ztbclan.com) |
| Date: | Sun, 31 Dec 2006 11:59:42 |
Just idea :
//Idea 1
TDirectTCPSender = class(TObject)
private
FSendTcp: TIdTCPClient;
FStatus: TSendThreadStatus;
public
constructor Create;
destructor Destroy; override;
function sendMsg(const destIP: string; const destPort: integer; data:
pointer): boolean;
end;
//this one just sending data and set flag of thread status, working, idle,
fail ....
TDTCPSubSender = class(TThread)
private
FTcpSender: TDirectTCPSender;
FdestIP: string;
FdestPort: integer;
Fdata: pointer;
FdataSize: integer;
public
constructor Create(sender: TDirectTCPSender; const destIP: string; const
destPort: integer; data: pointer; dataSize: integer);
procedure Execute; override;
end;
//this is one of mamy threads for send
TDTCPSenderThread = class(TThread)
private
FQueueMain: TDTCPSendQueue;
FSenders: array [0..15] of TDirectTCPSender;
FFreeSenders: TWordArray;
public
constructor Create(mainQ: TDTCPSendQueue; semaphorTHandle);
procedure Execute; override;
end;
//this is in loop,
//before loop creating all 16 subthreads
//in loop checking subthreads status and populating from queue, getting back
to retry queue if fail etc ...
//after loop free subthreads ...
//Idea 2
1. made semaphor for mutex Give to all subthreads handle and queue object.
Let all threads to run in loop all the time.
For a moment I still experimenting with my app and didn't have done that
well, because of that have ugly code which working ok too :
have Semaphor for 16 threads
main queue thread just checking queue and creating threads, thread made
connection, send, send back to queue if fail and die together with
TIdTcpClient. This is not eficient, temporary code for testings, just wanted
to say that this working too ...
"Jamie Dale" <dale_jamie@yahoo.com> wrote in message
news:4596e37f@newsgroups.borland.com...
>> A pool sounds like a good idea. That way, you are limited to what is
>> actually available, and your code can throttle itself according to
>> availability.
>
> Remy,
> Always looking for new ways of doing things, I'd like to ask how this
> could somehow be implemented?
>
> Any chance of a small piece of demo code?
>
> Thx
>
> JD
none