Listing 1: simple_send.pl An IP Telephone in 74 Lines of PERL
The Perl Journal, Fall 2000
 

Make a new outgoing connection.

 0    #!/usr/bin/perl

 1    use strict;
 2    use IO::File;
 3    use IO::Socket;

 4    use constant BUFSIZE => 4000;
 5    use constant DSP     => '/dev/dsp';
 6    $SIG{CHLD} = sub { exit 0 };

 7    my $dest = shift || 'prego';
 8    my $port = shift || 2007;
 9    my $sock = IO::Socket::INET->new("$dest:$port") || die "Can't connect: $!";
 10   warn "Connected, go ahead...\n";

 11   my $dsp = IO::File->new(DSP, "r+") || die "Can't open DSP: $!";

 12   my $child = fork();
 13   die "Can't fork: $!" unless defined $child;

 14   my $data;
 15   if ($child) { # parent process
 16       print $dsp $data while sysread($sock, $data, BUFSIZE);
 17       kill TERM => $child;
 18   } else {
 19       print $sock $data while sysread($dsp, $data, BUFSIZE);
 20   }