Solved

Indy TcpClient and server

Posted on 2002-07-29
3
538 Views
Last Modified: 2010-04-04
Hi everyone.

I am having troubles with indys tcpclient and tcpserver.

I can't see why it can give so many problems just to disconnect a thread. It gives errors and everything.

Just wan't to be able to disconnect a thread and free it correctly.

i have tried this in hope to disconnect client:
    AThread.Terminate;
    AThread.Free;
and also AThread.Connection.Disconnect;
but everything seems to give errors in some way, and nothing is been free correctly.

Hope someone knows how to do a simple disconnect without getting errors.

Thanks
0
Comment
Question by:Dennis9
3 Comments
 
LVL 12

Expert Comment

by:Lee_Nover
ID: 7186502
what error do you get ?
generally you only need to Disconnect the connection
the thread will be reused by the ThreadManager (hope you have one)
if there is no thread manager then the thread will be freed when the client disconnects
0
 

Accepted Solution

by:
junior2k earned 50 total points
ID: 7386762
Goal is : Terminate the TIDThread with its "TerminateAndWaitFor" method only.

Assume you have a Thread derived from TIdThread doing your connection, with a TIdTCPClient like MyClient inside.

1.) Override TIdThreads BeforeRun, Run and AfterRun.
2.) Connect somewhere in TMyIdThread.BeforeRun or TMyIdThread.Run
3.) Doing your work in the Run-Loop, terminate this loop if MyClient.Connected is false or Stopped is TRUE.
4.) Call Stop to disconnect manually, e.g. on errors
5.) Disconnect in AfterRun only if still connected:
  "if MyClient.Connected then MyClient.Disconnect;"
 
So, when terminating your TIdThread from the outside by calling "TerminateAndWaitFor", connection will be disconnected. On the other hand a 'reset by peer' will disconnect and terminate your thread also.
0
 

Expert Comment

by:SpideyMod
ID: 8280717
Force Accepted

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question