amir has asked for the wisdom of the Perl Monks concerning the following question:
Here is the code I have so far (at the moment, the client is just the STDIN and STDOUT filehandles), but I can't get it to even print out what the remote server is saying!
So, when something is entered in STDIN, it should be sent to the server, when the server sends something, it should be printed to STDOUT. Any help, code :), tips would be greatly appreciated!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); } } } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: IO::Select client and server in one
by fokat (Deacon) on Aug 01, 2002 at 02:31 UTC |