IdTCPClient connect problem

Giganews Newsgroups
Subject:IdTCPClient connect problem
Posted by: Alain Gosselin (agossel…@gggolf.ca)
Date:Fri, 30 Oct 2009

Hi,

I have thread which he read from a socket and check the CONNECTED
property of the TCPClient and if it's not connected, he call a RECONNECT
medthod to try a reconnection on the socket but in the RECONNECT method,
when he reach the CONNECT method, the thread look's like going nowhere,
it's look like my code never fall down in the except section.

procedure TConnection.ReConnect;
var
  S  : String;
  DT : TDateTime;
  MD5: TIdHashMessageDigest5;
  CS : TRTLCriticalSection;
begin
  InitializeCriticalSection(CS);
  EnterCriticalSection(CS);
  try
    if fTCPClient.Connected then
      fTCPClient.Disconnect;

    fTCPClient.Host := fHost;
    fTCPClient.Port := fPort;

    //Send authentification to the server
    DT := Now;
    S  := Params.UserId + '_' + FormatDateTime('yyyy-mm-dd',DT);
    MD5 := TIdHashMessageDigest5.Create;
    try
      S := LowerCase('<client>' + MD5.HashStringAsHex(S) + '</client>');
    finally
      MD5.Free;
    end;

    try
      fTCPClient.Connect;
      fTCPClient.Socket.Write(S);
    except on E:Exception do
        DoErrorEvent(errNotConnected,E.Message);
    end;
  finally
    LeaveCriticalSection(CS);
    DeleteCriticalSection(CS);
  end;
end;

Replies