Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Disconnect IdWhois from another thread(Indy 10)


This question is not answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 1 - Last Post: Jul 6, 2015 8:41 PM Last Post By: Remy Lebeau (Te...
Alex Smirnov

Posts: 1
Registered: 8/7/15
Disconnect IdWhois from another thread(Indy 10)  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jul 6, 2015 7:54 PM
My app dynamicaly creates threads like this:

unit Unit2;

interface

uses
Windows, System.Classes, IdWhois, IdException, IdIOHandlerStack, IdSocks, Unit1, IdGlobal,
RegExpr, SysUtils, Vcl.Forms, Vcl.ExtCtrls;

type
GetDomainInfoThread = class(TThread)
private
{ Private declarations }

IdWhois1: TIdWhois;

Domain: TDomain;

CurrentDomainsArr: TDomainArr;

Response: string;

procedure SyncOk;
procedure SyncEnd;
procedure SyncError;

procedure SyncUpdate;

protected
procedure Execute; override;
public
property ThCurrentDomainArr: TDomainArr write CurrentDomainsArr;
end;

implementation

{ GetDomainInfoThread }

procedure GetDomainInfoThread.Execute;
var
I: Integer;
begin
{ Place thread code here }

IdWhois1 := TIdWhois.Create;

I := 0;
while I < DomainsToGet do
begin
Domain := CurrentDomainsArr[I];

IdWhois1.IdWhois.Host := Domain.Host;
IdWhois1.ReadTimeout := ConnectionTimeOut * 1000;
IdWhois1.ConnectTimeout := ConnectionTimeOut * 1000;

try
Response := IdWhois1.WhoIs(Domain.DomainName); <--- stacks here. Established connection that never changes state and never respond

except
on E: EIdException do
begin
Synchronize(SyncError);
end;

if (Response <> '') then
Synchronize(SyncOk);

FreeAndNil(Domain);

Inc(I);

Synchronize(SyncUpdate);
end;

FreeAndNil(IdWhois1);

Synchronize(SyncEnd);
end;


procedure GetDomainInfoThread.SyncUpdate;
begin
Application.ProcessMessages;
end;

procedure GetDomainInfoThread.SyncError;
begin
ParsingErrors.Add(ErrorStr);
Inc(WhoisErrorsTotal);
WhoisErrorDomains.Add(Domain.DomainName);
end;

procedure GetDomainInfoThread.SyncOk;
begin
Inc(DomainsWhoisOk);
end;

procedure GetDomainInfoThread.SyncEnd;
begin
Dec(ThreadCount);
SetLength(CurrentDomainsArr, 0);
end;

end.

The problem is that sometimes connection hangs on IdWhois1.WhoIs(); and it never respond finishes timeouts or throw error/exception.. So how can it be disconnected from another thread? Thx.

Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Disconnect IdWhois from another thread(Indy 10)  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jul 6, 2015 8:41 PM   in response to: Alex Smirnov in response to: Alex Smirnov
Alex wrote:

The problem is that sometimes connection hangs on IdWhois1.WhoIs();
and it never respond finishes timeouts or throw error/exception..

What platform are you running this code on? What is the value of ConnectionTimeOut?

--
Remy Lebeau (TeamB)
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02