can't reconnect after disconnect

Giganews Newsgroups
Subject: can't reconnect after disconnect
Posted by:  Tarvirdi (m_tarvir…@isc.iranet.net)
Date: Mon, 25 Sep 2006

Dear friends,
I have a problem on reconnecting after disconnect a socket.
My code is as bellow

tcp := TIdTCPClient.Create;
  with tcp do begin
    Host := AIP;
    Port := APort;
    ConnectTimeout := AConnectTimeOut*1000;
    ReadTimeout := AReadTimeOut*1000;
    try
      connect;
Do somthings
      disconnect;
      sleep(1000);
      connect                            <<< get exception on this line
Do somthings
      disconnect;
  except
      on e : exception do
      ShowMessage(e.message);
  end;
The raised exception is
EIdAlreadyConnected :'Already connected.'
how force to disconnect? I tried IOHandler.Close instead of disconncet but
nothing changed
Thanks
Tarvirdi

Replies