问题
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