?
Solved

Indy TcpClient and server

Posted on 2002-07-29
3
Medium Priority
?
545 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

770 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