HANDLING MULTIPLE CLIENTS

HANDLING MULTIPLE CLIENTS

Name of Student

Name of Institution

 

 

Date of submission

Part 2

Write a program to implement a TCP concurrent server with the following functionalities:

 

When the client starts up, it should display a menu with the following service choices:

Reversal of the string

Count of words given the separator

Count of characters

Check for palindrome

#!/usr/bin/Perl

open {CHOICES, “choices”} or die “Can’t open choices: $!n”;

while {$line = <reversal of the string,count of words given the operator,count of characters,check for palindrome>} [

{$menu, $choices} = split{/ /, $line};

$choices[$menu ] .= $choices. ” “;

]

Provide the required functionality as a switch at the time of client invocation and convey it to the server as a part of the protocol by sending a message.

When the client has read from the screen what functions are able to be performed, he then sends a message to the server with his response on the choice desired (check for palindrome). The message is displayed as this;

#!/usr/bin/Perl

$check for palindrome;

print “$menu: $choice{$menu}tcheck for palindrome: $check for palindromen”;

]

Once your program is done and running, posts your response that includes the following:

 

Outline of the method of invoking your server and client programs

On the server;

$local = IO:::Socket:::INET->new{ Proto => ‘tcp’ LocalAddress => ‘localhost:8191’, Reuse => 1 } or fail “$!”;$local->listen{};$local->autoflush{1};

print “At your service. Waiting…n”;my $address; while {$address = $local->accept} } [ print “Linked from: “, $address->peerhost{}; print ” Port: “, $address->peerport{}, “n”; my $result; while {<$address>} [ last if m/^end/gi; print “Received: $_”; print $address $_; $result += $_; ] chomp; if {m/^end/gi} [

my $send = “result=$result”; print $address “$sendn”; print “Result: $sendn”; ] print “Locked connectionn”;

lock $address; print “At your service. Waiting…n”; ]

On the client;

$remote = IO:::Socket:::INET->new{ Proto => ‘tcp’, PeerAddress=> ‘localhost’, PeerPort=> “8191”, Reuse => 1, } or fail “$!”;print “Linked to “, $remote->peerhost, ” on port: “, $remote->peerport, “n”;$remote->autoflush{1}; while {<>} [ print $remote $_; last if m/^end/gi; my $line = <$remote>; if {$line ne $_} [ print “Error in sending outputn”; exit; ]]my $res = <$remote>; $res =~ m/result={d*}/gi; print “Result: $1n”; print “Client terminatedn”; lock $remote

The server and client window screenshots for a sample service selected by the client

(***************)

The source code for the programs is 8191

HANDLING MULTIPLE CLIENTS

HANDLING MULTIPLE CLIENTS

Name of Student

Name of Institution

 

 

Date of submission

Part 2

Write a program to implement a TCP concurrent server with the following functionalities:

 

When the client starts up, it should display a menu with the following service choices:

Reversal of the string

Count of words given the separator

Count of characters

Check for palindrome

#!/usr/bin/Perl

open {CHOICES, “choices”} or die “Can’t open choices: $!n”;

while {$line = <reversal of the string,count of words given the operator,count of characters,check for palindrome>} [

{$menu, $choices} = split{/ /, $line};

$choices[$menu ] .= $choices. ” “;

]

Provide the required functionality as a switch at the time of client invocation and convey it to the server as a part of the protocol by sending a message.

When the client has read from the screen what functions are able to be performed, he then sends a message to the server with his response on the choice desired (check for palindrome). The message is displayed as this;

#!/usr/bin/Perl

$check for palindrome;

print “$menu: $choice{$menu}tcheck for palindrome: $check for palindromen”;

]

Once your program is done and running, posts your response that includes the following:

 

Outline of the method of invoking your server and client programs

On the server;

$local = IO:::Socket:::INET->new{ Proto => ‘tcp’ LocalAddress => ‘localhost:8191’, Reuse => 1 } or fail “$!”;$local->listen{};$local->autoflush{1};

print “At your service. Waiting…n”;my $address; while {$address = $local->accept} } [ print “Linked from: “, $address->peerhost{}; print ” Port: “, $address->peerport{}, “n”; my $result; while {<$address>} [ last if m/^end/gi; print “Received: $_”; print $address $_; $result += $_; ] chomp; if {m/^end/gi} [

my $send = “result=$result”; print $address “$sendn”; print “Result: $sendn”; ] print “Locked connectionn”;

lock $address; print “At your service. Waiting…n”; ]

On the client;

$remote = IO:::Socket:::INET->new{ Proto => ‘tcp’, PeerAddress=> ‘localhost’, PeerPort=> “8191”, Reuse => 1, } or fail “$!”;print “Linked to “, $remote->peerhost, ” on port: “, $remote->peerport, “n”;$remote->autoflush{1}; while {<>} [ print $remote $_; last if m/^end/gi; my $line = <$remote>; if {$line ne $_} [ print “Error in sending outputn”; exit; ]]my $res = <$remote>; $res =~ m/result={d*}/gi; print “Result: $1n”; print “Client terminatedn”; lock $remote

The server and client window screenshots for a sample service selected by the client

(***************)

The source code for the programs is 8191

Leave a Reply