Newsgroups : Borland : borland.public.delphi.internet.winsock : 2007 Mar : Re: Indy10 - TIdTCPConnection, Open/Close, ReadLnTimedOut, Read Thread

www.cryer.info
Managed Newsgroup Archive

Re: Indy10 - TIdTCPConnection, Open/Close, ReadLnTimedOut, Read Thread

Subject:Re: Indy10 - TIdTCPConnection, Open/Close, ReadLnTimedOut, Read Thread
Posted by:"Michael Stieler" (michael.stiel..@rie.eu)
Date:Fri, 30 Mar 2007 16:07:03

Remy Lebeau (TeamB) schrieb:

>
> No.  You should not be creating a TIdTCPConnection directly in the
> first place.  You should be using a TIdTCPClient instead, ie:
>

Thank you, that is the way I first wanted to do it. Then ran into
problems and tried about every method of connecting and getting data. It
now works better but I got another problem back I hoped to have eliminated:

I now use a TIdTcpClient I create in a self-built TComponent class. This
class has a Connect routine that looks like this:

conn.Host := ...
conn.Port := ...
RIELog('Connect');
conn.Connect;

RIELog is a global Logging routine that adds a line to a Memo box.
In the OnConnected Event Handler there is

RIELog('Connected');
readThread := TReadThread.Create(conn);
readThread.OnRead := Read;
readThread.OnTerminate := ThreadTerminated;

After disconnection I terminate the thread with .Terminate and Free it
in the OnTerminate event handler.

Now my program connects, disconnects, connects, disconnects.. and on the
second or third or even fifth attempt, it deadlocks. The last Log entry
is Connected and debugger is in CPU mode with no call stack or links to
ntdll.RtlTryEnterCriticalSection. I don't understand why, and debug info
makes the .Connect method of the TcpClient suspicious.

The class methods run in main thread context, except the OnRead handler
which is triggered by the read thread. Another thread is holding another
TCP Connection with only Write and ReadLn commands.

Any tips?

Michael Stieler

Replies:

In response to:

www.cryer.info
Managed Newsgroup Archive