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; } }

In reply to Win98 socket woes by Dinosaur

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.