CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Adding 2 numbers in a Multiclient environment

 



zak100
User

Jul 30, 2014, 10:26 AM

Post #1 of 1 (142 views)
Adding 2 numbers in a Multiclient environment Can't Post

Hi,
I want to add two numbers. I have multiple clients but one server. The problem is that if 'client 1' sends 1 and 'client 2' sends 3, server prints 4. I want that server should wait for 2 numbers from each client and then print the sum. I have used 'fork' but its not solving the problem.
Server Code

Code
#!C:/Perl64/bin/perl.exe 
use IO::Socket::INET;
$server=IO::Socket::INET->new(LocalPort=>'5465',Proto=>'UDP');
$pid = fork ( );
if ($pid == 0) {
while(1) {
$server->recv($num1,1024);
print("\nnum1=", $num1);
$server->recv($num2,1024);
print("\nnum2=", $num2);
print ("\nSum=" , $num1 + $num2 + "\n");
$|++;
}
}


Client Code

Code
#!C:/Perl64/bin/perl.exe 
use IO::Socket::INET;

while(1) {
$client=IO::Socket::INET->new(PeerPort=>'5465',Proto=>'UDP', PeerAddr=>'127.0.0.1');
print("Enter the first number\n");
$Num1=<STDIN>;
$client->send($Num1);
print("Enter the second number\n");
$Num1=<STDIN>;
$client->send($Num1);

}


Please guide me.

Zulfi.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives