in reply to Re^2: Message Passing b/w processes , that works both in windows and Linux
in thread Message Passing b/w processes , that works both in windows and Linux

You use read($sock) not <$sock> (or sysread or recv).

Note that you might also run into the problem I was able to work around at Re^2: ActiveState woes : Is it EOF-blind? (perl bug).

And you probably want to replace fork with either Win32::Process::Create( $^X, qq(perl "$0" ...), ... ) or system( 1, $^X, $0, ... ) (this Win32-specific use of system is documented in perlport). So write a wrapper that uses fork if not on Win32.

- tye        

Replies are listed 'Best First'.
Re^4: Message Passing b/w processes , that works both in windows and Linux (read)
by ikegami (Patriarch) on Jun 09, 2009 at 01:24 UTC

    Switching to read alone won't be sufficient (in the child). There would be no way of knowing whether the message has been fully received.

      Given the sample code, actually that particular problem wouldn't apply either in the case of pipes or sockets. I'm not sure whether the code is actually complete, but it looks like the messages being passed are quite short, which means that they won't ever be fragmented. I guess you could still have a problem with getting two messages at once, though.

      Likewise, using "\n" as your message terminator won't work if your messages might contain "\n"s (I wasn't convinced such was impossible based on the offered code). But it seems at least a good starting point.

      - tye