in reply to pass ARGV to STDIN
From IO::Socket::INET docs:
If "Listen" is defined then a listen socket is created, else if the socket type, which is derived from the protocol, is SOCK_STREAM then connect() is called.
You're using a connect() socket only, so your process family won't talk much. You need at least one process listening and the other connecting so they can speak; but please note that it will be a client/server (i.e. child/parent) dialog, so the parent won't be able to say a thing until the child requests. If you need a different kind of dialog, then you should change your path to the IPC route.
Update: This is the classic ping-pong example, that you could find helpful...
#!/usr/bin/perl use IO::Socket::INET; use strict; use warnings; if (my $pid = fork()) { my $listen = IO::Socket::INET->new( LocalAddr => 'localhost', LocalPort => 9000, Proto => 'tcp', Listen => 1, ) or die "Cannot create listening socket: $!\n"; my $client = $listen->accept() or die "Cannot get a connection: $!\n"; $client->autoflush(1); while (defined(my $line = <$client>)) { print "server < $line"; sleep 1; pong($client); } } else { print "waiting for parent to setup...\n"; sleep 1; my $sock = IO::Socket::INET->new( PeerAddr => 'localhost', PeerPort => 9000, Proto => 'tcp', Type => SOCK_STREAM ) or die "Cannot create connecting socket: $!\n"; $sock->autoflush(1); ping($sock); while (defined(my $line = <$sock>)) { print "client < $line"; sleep 1; ping($sock); } } sub ping { my ($fh) = @_; print "client > ping\n"; print {$fh} "ping\n"; } sub pong { my ($fh) = @_; print "server > pong\n"; print {$fh} "pong\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: pass ARGV to STDIN
by icylisper (Initiate) on Mar 08, 2008 at 06:29 UTC | |
by almut (Canon) on Mar 08, 2008 at 08:36 UTC | |
by icylisper (Initiate) on Mar 08, 2008 at 14:27 UTC | |
by alexm (Chaplain) on Mar 08, 2008 at 09:00 UTC |