Dinosaur has asked for the wisdom of the Perl Monks concerning the following question:
Sort of in the same vein as Bi directional Socket question:
I can't get a pair of processes to communicate by socket, under Win98 with ActiveState perl 5.6.1.
I've read the Perl Cookbook ch. 17 advice, and also the relevant sections of Mastering perl/Tk (since that's what I'm trying to do, move some heavy lifting to a separate process so as not to slow down GUI response). What I'm doing, I think, is right in line with their recommendations. I've tried various permutations of parameters, with no success.
Code is below. When I run it, I get the following messages:
child started IO::Socket::INET=GLOB(0x204aeb8) child read failed: Invalid argument at E:\Perls\sock_hop.pl line 63. parent started IO::Socket::INET=GLOB(0x176541c) parent sending parent sending parent sending parent write failed: Invalid argument
... of which the failed read in the child seems to be the smoking gun. "Invalid argument" presumably refers to the file handle -- but what's its problem?
If anyone here can take a minute to look at the attached code snippet, I'd be grateful.
--Dinosaur
use strict; use warnings; use IO::Socket; sub process; sub parent; sub child; use vars qw[$PARENT $CHILD]; process; exit; sub process { $PARENT = IO::Socket::INET->new( Type => SOCK_STREAM, Proto => 'tcp', LocalHost => 'localhost', LocalPort => 9969, Listen => 5, ); die "parent socket failed: $!\n" unless defined $PARENT; $CHILD = IO::Socket::INET->new( Type => SOCK_STREAM, Proto => 'tcp', PeerAddr => 'localhost', PeerPort => 9969, ); die "child socket failed: $!\n" unless defined $CHILD; if (my $pid = fork()) { close $PARENT; parent; } else { die "fork failed: $!\n" unless defined $pid; close $CHILD; child; } } sub parent { print STDERR "parent started $CHILD\n"; while (1) { print STDERR "parent sending\n"; print $CHILD "Hello from parent\n" or die "parent write failed: +$!\n"; sleep 2; } } sub child { print STDERR "child started $PARENT\n"; while (1) { my $line = readline ($PARENT); die "child read failed: $!" unless defined $line; print STDERR $line; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Win98 socket woes
by perlplexer (Hermit) on Apr 08, 2002 at 14:00 UTC | |
by Dinosaur (Beadle) on Apr 08, 2002 at 18:50 UTC |