delphi code does not connect me to irc server -
hello doing program in delphi console, xe2 delphi , indy using sockets , problem have code done when connect server receive no response ping pong.
the code follows:
program project1; {$apptype console} {$r *.res} uses system.sysutils, idtcpclient; var irc: tidtcpclient; code: string; begin try irc := tidtcpclient.create(nil); irc.host := 'irc.freenode.net'; irc.port := 6667; irc.connect; irc.socket.write('nick tester'); irc.socket.write('user tester 1 1 1 1'); irc.socket.write('join #tester'); if irc.socket.connected = true begin writeln('yeah'); while (1 = 1) begin code := irc.socket.readstring(9999); if not(code = '') begin writeln(code); end; end; end else begin writeln('nay'); end; except on e: exception writeln(e.classname, ': ', e.message); end; end. anyone can me?
you not sending crlf after each command send. use tidiohander.writeln() instead of tidiohandler.write().
also, call tidiohandler.readstring() not exit until 9999 bytes have been received. not want happen. irc line-based protocol. should using tidiohandler.readln() instead of tidiohandler.readstring().
try more instead:
program project1; {$apptype console} {$r *.res} uses system.sysutils, idtcpclient; var irc: tidtcpclient; code: string; begin try irc := tidtcpclient.create(nil); try irc.host := 'irc.freenode.net'; irc.port := 6667; try irc.connect; except writeln('nay'); exit; end; writeln('yeah'); irc.iohandler.writeln('nick tester'); irc.iohandler.writeln('user tester 1 1 1 1'); irc.iohandler.writeln('join #tester'); repeat code := irc.iohandler.readln; writeln('[recv] ' + code); if textstartswith(code, 'ping ') begin fetch(code); irc.iohandler.writeln('pong ' + code); writeln('[sent] pong ' + code); end; until false; irc.free; end; except on e: exception writeln(e.classname, ': ', e.message); end; end. with being said, should using tidirc component instead. try this:
program project1; {$apptype console} {$r *.res} uses system.sysutils, idirc, idcontext, idglobal; procedure ircraw(aself: pointer; asender: tidcontext; ain: boolean; const amessage: string); begin writeln(iif(ain, '[recv] ', '[sent] ') + amessage); end; var irc: tidirc; m: tmethod; begin try irc := tidirc.create(nil); try irc.host := 'irc.freenode.net'; irc.port := 6667; irc.nickname := 'tester'; irc.username := 'tester'; m.code := @ircraw; m.data := irc; irc.onraw := tidircrawevent(m); try irc.connect; except writeln('nay'); exit; end; writeln('yeah'); irc.join('#tester'); repeat sleep(10); until somecondition; irc.free; end; except on e: exception writeln(e.classname, ': ', e.message); end; end.
Comments
Post a Comment