Search code examples
delphiindyirc

Delphi Indy IRC


Delphi version : XE2, Indy version: 10.5.8.0. I have three procedures and all work fine until internet connection gets lost. When it will happen and after that I will try sending message then I can't reconnect when internet will be back. Can't close program (after on close program be not visible, but will use 100 cpu usage). Without "try, exception" there is a Socket Error #1053 on IdIRC1.Say and on Close. Thanks for help.

///Connection:

    procedure TForm1.Button5Click(Sender : TObject);
    begin
      try
        IdIRC1.Nickname := 'zzz';
        IdIRC1.Password := 'kkk';
        if IdIRC1.Connected then
          IdIRC1.Disconnect;
        IdIRC1.Connect;
        IdIRC1.Join('#' + edit3.Text);
      except
        ShowMessage('ggg');
      end;
    end;

///Send message:

procedure TForm1.Button3Click(Sender : TObject);
begin
 try
    IdIRC1.Say('#' + edit3.Text, edit2.Text);
    if (edit2.Text <> '') and (IdIRC1.Connected) then
    begin
      memo6.Lines.Add(edit2.Text);
      Edit2.Clear;
    end
    else
      ShowMessage('xxx');
 except
    ShowMessage('yyy');
 end;
end;



///On close:
  try
    IdIRC1.Disconnect;
  except
  end;

Solution

  • When you encounter an error accessing the connection, such as because the connection was lost, you need to call Disconnect() and you need to clear the IOHandler.InputBuffer if it still has unread data in it. Disconnect() does not clear the InputBuffer, by design. If the InputBuffer is not empty, Connected() will return True even if the physical socket is disconnected.