Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Indy TcpClient and server

Posted on 2002-07-29
3
Medium Priority
?
548 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 150 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

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

636 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