1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
|
#!/usr/local/bin/perl
#
# pRPC - Perl RPC, package for writing simple, RPC like clients and
# servers
#
# client.t is both a test script and an example of how to create
# clients with the package
#
#
# Copyright (c) 1997 Jochen Wiedmann
#
# You may distribute under the terms of either the GNU General Public
# License or the Artistic License, as specified in the Perl README file.
#
# Author: Jochen Wiedmann
# Am Eisteich 9
# 72555 Metzingen
# Germany
#
# Email: wiedmann@neckar-alb.de
# Phone: +49 7123 14881
#
#
# $Id: client.t,v 0.1001 1997/09/14 22:53:30 joe Exp $
#
require ((-f "lib.pl") ? "lib.pl" : "t/lib.pl");
############################################################################
#
# This is main().
#
############################################################################
{
# Force output being written immediately
$| = 1;
print "1..14\n";
$SIG{'PIPE'} = sub { print STDERR "Got signal PIPE.\n"; };
#
# We'd prefer to do the following as part of the Server()
# function. This would be fine, if we'd bind on a well
# known port. In our case we don't care for the port
# the only important thing is, that the child will
# now about it.
#
my $sock = IO::Socket::INET->new('Proto' => 'tcp',
'Listen' => 10,
'Reuse' => 1);
if (!defined($sock)) {
print STDERR "Cannot create server socket.\n";
exit 10;
}
# Fork into a client and a server
if (!defined($childPid = fork())) {
print STDERR "Cannot fork(): $!\n";
exit 10;
} elsif ($childPid == 0) {
#
# We are the child; create a server
#
Server($sock);
exit 0;
}
#
# We are the parent; wait some seconds until the server is up
# and then try to connect.
#
sleep 5;
Client($sock->sockhost, $sock->sockport);
}
|