use Socket; use Socket6; use IO::Select; $| = 1; my($host,$port) = ("irc.weblook2k.com",6667); @res = getaddrinfo($host, $port, AF_UNSPEC, SOCK_STREAM); $family = -1; ($family, $socktype, $proto, $saddr, $canonname, @res) = @res; ($host, $port) = getnameinfo($saddr, NI_NUMERICHOST | NI_NUMERICSERV); socket(SOCK, $family, $socktype, $proto); connect(SOCK, $saddr) or die("connect error!"); my $s = new IO::Select(); $s->add(\*STDIN); $s->add(\*SOCK); while(1) { my $rh_set = IO::Select->select($s, $s, undef, 0.1); my $rh; foreach $rh (@$rh_set) { if($rh == $s) { $ns = $rh->accept(); $s->add($ns); } else { # read data $buf = <$rh>; # should use sysread() maybe? if($buf) { print STDOUT $buf; } else { $rh_set->remove($rh); close($rh); } } } }