Newsgroups : Borland : borland.public.delphi.internet.winsock : 2006 Nov : Listener Thread on TidTCPClient - ReadLn?

www.cryer.info
Managed Newsgroup Archive

Listener Thread on TidTCPClient - ReadLn?

Subject:Listener Thread on TidTCPClient - ReadLn?
Posted by:"PeaShooter_OMO" (..@me.com)
Date:Mon, 27 Nov 2006 12:21:46

Good day

I am using Indy 9.00.10 and Delphi 7

From previous posts I was told to create a listener thread on the client
side for my TidTCPClient if I wanted the component to receive messages from
the server whenever the server wanted to send them.

So for testing I created a thread using TidThread. I looked at the TidTelnet
component, so I also pointed a FTCPClient in this thread to the TidTCPClient
and in the Run procedure of the Thread I did the following:

procedure THuhClientReadThread.Run;
begin
    FString := '';
    FString := FTCPClient .ReadLn;
    Synchronize(Form1.ProcAddLine); // to add the line received to a memo
end;

Is the above the correct way of doing it?

I found that if nothing is sent from the server then this thread will wait
on the "FString := FTCPClient .ReadLn;" line for whenever something comes
in. I think it is because no read Timeout was specified.
Is that correct. Can I use it without the timeout and is it preferred?

I want to use the above for a program I am writing where the Client will do
things and send stuff to the server and the server will also send stuff back
whenever it wants to. It will not always happen at one
time. I want to hand the line that I read from the thread to the
TidTCPClient but I want to be sure that the TidTCPClient can receive it and
process it. Should I write another thread that collects all the Lines
into a buffer and process them sequentially and forwards them to the
TidTCPClient whenever the TidTCPClient  can process it? For example:

procedure THuhClientReadThread.Run;
begin
    FString := '';
    FString := FTCPClient .ReadLn;
    BufferThread.Lines.Add(FString);  // adds to a Thread Safe
TIdThreadSafeStringList
end;

What shoud I do? I am looking for the most correct way to handle this.

Thank you

Replies:

www.cryer.info
Managed Newsgroup Archive