Link to home
Start Free TrialLog in
Avatar of ellandrd
ellandrdFlag for Ireland

asked on

CLIENT/SERVER in Perl/UNIX

What I want to achieve:
Send message from Server to Client using PERL on a UNIX OS

Whats happens in both scripts:
All the Server is doing is either sending a number back to Client or a string back to the Client, depending on my choice.

// variables set up with values
$messageNumber = 20;
$messageString = "12345,12345,abcd,asdf,12345";

//send message to client
print <SERVER> $messageNumber,"\n";  <<<<<<<<<< here i can choose what to send back to client like i said above!

I want to check if its a number of a string?

but cant get it to work?


CLIENT.PL
----------------------
use Socket;
use FileHandle;
autoflush CLIENT 1;

$filename = "###";

socket(CLIENT, PF_UNIX, SOCK_STREAM, 0) or die "Socket: $!";
connect(CLIENT, sockaddr_un($filename)) or die "Connect: $!";

while ($display = <CLIENT>)
{
      if ($display =~ /#/g)
      {
            print "The number from the server was: $display\n\n";
            close CLIENT;
      }      
      elsif ($display > " ")      
      {
            chomp ($display);
            
            ($uid, $pid, $state, $fname, $size) = split(",", $display);
            
            format =
            @<<<<<< @<<<<<< @<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<<<<<<<< @<<<<<<<<<<
            $uid, $pid, $state, $fname, $size
            .

            format STDOUT_TOP =
            Page No: @<
            $%
            UID      PID       State             Filename                Virtual Size
            ----       -----      ------------      -------------------          ------------
            .
            
            write;
      }
      close CLIENT;
}
close CLIENT;


Can anybody see any errors?

Nothing works?

Ellandrd

Avatar of ozo
ozo
Flag of United States of America image

I think you want
print SERVER $messageNumber,"\n";
not
print <SERVER> $messageNumber,"\n";
Avatar of ellandrd

ASKER

OK that fixed that part, but how come it keeps printing out my the formating in the second IF statement if i passed a number to the client? it should just print:

The number from the server was: 20

but it prints out:

UID     PID      State           Filename              Virtual Size
----      -----     ------------     -------------------         ------------
20

Ellandrd
$display =~ /#/g
will only be true when $display contains a "#" character
"20\n" does not contain a "#" character
perl -Mdiagnostics -we '$display=20;if( $display > " " ){}'
Argument " " isn't numeric in numeric gt (>) at -e line 1 (#1)
    (W numeric) The indicated string was fed as an argument to an operator
    that expected a numeric value instead.  If you're fortunate the message
    will identify which operator was so unfortunate.
ASKER CERTIFIED SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial