Jaspersan has asked for the wisdom of the Perl Monks concerning the following question:

I really need help with sockets. If you would take a look at the script im writing. It can be downloaded here:
http://wintermarket.org:81/~jasper/shitz/code/pollux11b.zip

What i am trying to do in this script, is have it connect to an irc server and run as a bot. But the problem is that it dosnt stay connected to the server. It goes through the code once then ends. And it really needs to stay connect. I think i need either a 'good' loop or to make some child proccesses for the socket, but im not sure.

any help what so ever would be GREATLY appriciated.
thanks in advanced
^jasper <jasper@wintermarket.org>

Replies are listed 'Best First'.
Re: Really Need Help with SOCKETS
by TheHobbit (Pilgrim) on Apr 19, 2002 at 14:56 UTC

    Hi,
    I hope I do not look too nasty but... Try to have a look at the Net::IRC module. It does that for you and more beside :))

    As it said inn the module man page:

    use Net::IRC; $irc = new Net::IRC; $conn = $irc->newconn(Nick => 'some_nick', Server => 'some.irc.server.com', Port => 6667, Ircname => 'Some witty comment.'); $irc->start;
    is all you need.

    By the way, doing it through Socket, implies reading very carefully the IRC rfc.

    Cheers
    Leo TheHobbit
    GED/CS d? s-:++ a+ C++ UL+++ P+++>+++++ E+ W++ N+ o K? !w O? M V PS+++
    PE-- Y+ PPG+ t++ 5? X-- R+ tv+ b+++ DI? D G++ e*(++++) h r++ y+++(*)
      I was going to try to use the least amount of third party modules. I've allready read the IRC rfc. But i guess i can go ahead and use NET:IRC until i get the whole sockets problem fixed :)

      Thanks for the help
      ^jasper <jasper@wintermarket.org>
Re: Really Need Help with SOCKETS
by Jaspersan (Beadle) on Apr 19, 2002 at 14:22 UTC
    $sock = IO::Socket::INET->new ( PeerAddr => $server, PeerPort => $sport, Proto => "tcp" ); if($sock==undef) { print "Could not connect to Host!\n"; exit; } while (1) { #the problem is that it needs to stay connected to the server #so it can continuously send/receive data or wait for data to #get data from the server next unless $sock->recv($buff,5000); #get data? if possible print <$buff>; #i had a bunch of code here that parses/uses the data from the ser +ver. }