Solved

Indy TcpClient and server

Posted on 2002-07-29
3
534 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
Comment Utility
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
Comment Utility
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
Comment Utility
Force Accepted

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

762 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now