Child handle and parent handle : Socket « Network « Perl






Child handle and parent handle

    

use Socket;
use IO::Handle;

socketpair(CHILDHANDLE, PARENTHANDLE, AF_UNIX, SOCK_STREAM, PF_UNSPEC)
    or  die "Could not create socketpair.";

CHILDHANDLE->autoflush(1);
PARENTHANDLE->autoflush(1);

if ($pid = fork) {
    close PARENTHANDLE;
    print CHILDHANDLE "Hello from the parent!\n";
    $line = <CHILDHANDLE>;
    print "Parent read: $line";
    close CHILDHANDLE;
    waitpid($pid,0);
} else {
    close CHILDHANDLE;
    $line = <PARENTHANDLE>;
    print "Child read: $line";
    print PARENTHANDLE "Hello from the child!\n";
    close PARENTHANDLE;
    exit;
}

   
    
    
    
  








Related examples in the same category

1.Time Server with Socket
2.Using Socket to call a Perl CGI
3.Socket server
4.Perl Modules for Networking with Sockets
5.Open a socket
6.Post query to a CGI
7.Query a Perl CGI
8.Listen to a port
9.Using regular expresion to validate an IP address
10.Daytime client, using symbolic host and service names
11.Add a host, delete a host, add a user, delete a user, ping a host, list processes, list filesystems, lists hosts, and kill a process.
12.A Perl TCP server without the Socket module.
13.A Simple script to update your host/ip with dyndns.org service.