KevinZwack has asked for the wisdom of the Perl Monks concerning the following question:
My program and this snippet always hang up after typing something to STDIN, like "help". Note that I am using the same unix $host in all cases.#!/usr/bin/perl5.8.8 -w use strict; use warnings; use threads; use IO::Socket qw(:DEFAULT :crlf); my $host = shift || 'localhost'; my $socket = IO::Socket::INET->new(PeerAddr => $host, PeerPort => 'ftp', Proto => 'tcp', Type => SOCK_STREAM, Timeout => 5) or die "Couldn't connect to remote host: $@\n"; my $listenerThread = threads->create(\&listener, $socket) or die "$@\n +"; while (<STDIN>) { chomp; print $socket $_, CRLF; }; exit(0); sub listener($) { my $s = shift; my $data; $/ = CRLF; syswrite(STDOUT, $data) while sysread($s, $data, 2048); print "\nListener exiting\n"; }; __END__
Any ideas would be appreciated.
Thanks,
Kevin Zwack
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Sockets and threads, oh my!
by BrowserUk (Patriarch) on Jun 17, 2006 at 08:54 UTC | |
by KevinZwack (Chaplain) on Jun 19, 2006 at 21:07 UTC | |
by BrowserUk (Patriarch) on Jun 19, 2006 at 21:44 UTC | |
by KevinZwack (Chaplain) on Jun 20, 2006 at 17:19 UTC |