Hello,
i tried to avoid , a perl script calling an another perl script using the sub() in main script, but the problem is i am not getting the output of that sub routine in the array
here is the code i am using :::
i tried to call &server subroutine in main script [my @output = readpipe(&server);]
but did not get any thing in the array @output rather i am getting on screen which i need for further processing (got a 1 connection from:)
could anybody suggest??
while(1)
{
print"Hello, Waiting For Connection From The Client\n";
#my @output = readpipe("server.pl");
my @output = readpipe(&server);
#my @output = readpipe(server());
print"Bye, Confirmed The Connection from Client\n";
print @output;
open FILE, ">server.txt" or die $!;
print FILE @output;
close FILE;
$data_file="server.txt";
open(ROCK, $data_file)|| die("Could not open file!");
@raw_data=<ROCK>;
@COUNT_PS =split(/ /,$raw_data[1]);
my $LOOP_COUNT_PS_3 = $COUNT_PS[2];
my $value = "$LOOP_COUNT_PS_3";
print "$value";
open FILE, ">value.txt" or die $!;
print FILE $value;
close FILE;
close(ROCK);
sleep 5;
#if ($value)
#{
system("iperf.exe -u -c 10.232.62.151 -p 5001 -t 5 -b 3600k -i 1");
#}
}
#!/usr/bin/env perl
#use strict;
#use warnings;
sub server{
#! /usr/bin/perl -w
# server0.pl
#--------------------
#use strict;
use Socket;
# use port 7890 as default
my $port = shift || 7870;
my $proto = getprotobyname('tcp');
# create a socket, make it reusable
socket(SERVER, PF_INET, SOCK_STREAM, $proto) or die "socket: $!\n";
setsockopt(SERVER, SOL_SOCKET, SO_REUSEADDR, 1) or die "setsock: $!\n";
# grab a port on this machine
my $paddr = sockaddr_in($port, INADDR_ANY);
#my $paddr = inet_aton("192.168.16.2");
# bind to a port, then listen
bind(SERVER, $paddr) or die "bind: $!\n";
listen(SERVER, SOMAXCONN) or die "listen: $!\n";
print "SERVER started on port $port \n";
$value = 0;
# accepting a connection
my $client_addr;
while ($client_addr = accept(CLIENT, SERVER))
{
# find out who connected
my ($client_port, $client_ip) = sockaddr_in($client_addr);
my $client_ipnum = inet_ntoa($client_ip);
my $client_host = gethostbyaddr($client_ip, AF_INET);
$count=++$value;
# print who has connected
print "got a $count connection from: $client_host","[$client_ipnum] \n";
# send them a mesage, close connection
print CLIENT "This is $count Connection from the server\n";
#print CLIENT "$count\n";
close CLIENT;
close SERVER;
}
/rocky..
}