Solved

Indy TcpClient and server

Posted on 2002-07-29
3
539 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi XE10, DigitalPersona Fingerprint reader and MySQL 6 329
tvirtualstringtree freeze when load too manny images 10 71
Base1 Encode/Decode 3 81
MS Access from Delphi 31 60
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
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…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

860 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