Why won't TIdIRC connect to channel? Is there a better component?

 ̄綄美尐妖づ 提交于 2019-12-25 05:14:40

问题


I've been struggling with the crap documentation of Google and can't get the program to join the channel even though it connects to the server fine. (It says Connected to server)

//On Form Make
procedure TForm2.FormCreate(Sender: TObject);
  begin
   IdIRC1.Connect();
  end;

//on connected
procedure TForm2.IdIRC1Connected(Sender: TObject);
  begin
   ShowMessage('Connected to server');
   IdIRC1.Join('#TheChannel', 'password');
  end;      

Once i close the form an error comes up saying:

Project raised exception class EIdException with message 'Not Connected'

Also once connected what functions do i use to talk on the channel/check input? And what other IRC connection options (components) are there for Delphi applications?

ANY HELP WOULD BE APPRECIATED, GOOGLE HAS NOTHING ON THIS REALLY. All i want is to be able to connect/check channel chat messages & talk on the chat; Simple String IO through IRC...


回答1:


Guess you are not filling all the server requirements. Just IdIrc.Connect isn't enought, this works for me:

FIRC.Host:= 'irc.freenode.org';
FIRC.Port := 6667;
FIRC.Username:= 'SapoIndy';
FIRC.Nickname:= 'SapoIndy';
FIRC.RealName:= 'Fabio Gomes';
FIRC.Connect;

FIRC.Join('#TheChannel');

To figure out what is going on, you need to get the output of some events, I had implemented these:

FIRC.OnStatus:= @Status;
FIRC.OnNotice:= @Notice;
FIRC.OnMOTD:= @MOTD;

Get some events up and you should figure out what the server is telling you, don't go with trial and error.

And about sending and receiving messages, I've implemented some of this some time ago, here is the project, it was made using Lazarus.

https://bitbucket.org/fabioxgn/irc/src/b510d73e553d/main.pas




回答2:


Do not call Join() in the OnConnected event. That event simply means the underlying socket connection is established. Connect() is still running, and has not actually logged into the IRC server yet when the OnConnected event is triggered. Wait until Connect() exits before issuing any commands:

procedure TForm2.FormCreate(Sender: TObject); 
begin 
  IdIRC1.Connect; 
  ShowMessage('Connected to server'); 
  IdIRC1.Join('#TheChannel', 'password'); 
end; 


来源:https://stackoverflow.com/questions/10679159/why-wont-tidirc-connect-to-channel-is-there-a-better-component

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!