Re: [Socket Programming]: Need info for Client / Server scenario

2004-05-31 Thread James Edward Gray II
On May 31, 2004, at 11:10 AM, <[EMAIL PROTECTED]> wrote:
Hi James,
Can you suggest me what this POE is?
POE or Perl Object Environment is a multitasking framework.
Where can I get info regarding this?
http://poe.perl.org/
James
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



RE: [Socket Programming]: Need info for Client / Server scenario

2004-05-31 Thread suresh.pasupula

Hi James,

Can you suggest me what this POE is?
Where can I get info regarding this?

Thanks and regards
Suresh

-Original Message-
From: James Edward Gray II [mailto:[EMAIL PROTECTED]
Sent: Monday, May 31, 2004 9:19 PM
To: Suresh Pasupula (WT01 - EMBEDDED & PRODUCT ENGINEERING SOLUTIONS)
Cc: [EMAIL PROTECTED]
Subject: Re: [Socket Programming]: Need info for Client / Server
scenario

On May 30, 2004, at 11:06 PM, <[EMAIL PROTECTED]> wrote:

> Hi,

Howdy.

> I need some good links for understanding socket programming (Client /
> Server programming).

Not a link specifically, but I feel I would be letting you down if I
didn't mention Network Programming with Perl.  That is an excellent
book that covers exactly what you're after and much more.  I strongly
recommend it.

> I have written some scripts for multiple clients and a server (Forking
> Server).
>
> But I am facing some problems - the server data has to be shared among
> all the child processes - does this happen when we fork - what should
I
> do for this to happen.

There are basically three major approaches to these kinds of servers: 
Forking, Threaded, and Non-Blocking IO.  As others have mentioned,
Forking is probably not the way to go in this instance.  You want one
of the other two.

A Threaded server is the easier of the two to write.  Unfortunately,
it's still plenty involved so I do suggest referencing to book I
mentioned above.

Another option you might want to look into is POE, which will probably
greatly simplify this kind of thing.  It have a learning curve you
would need to pass too, but can be useful in many applications. 
Unfortunately, this option isn't covered by the Networking book, so
you'll have to use the POE documentation, if you go this way.

Good luck.

James


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Confidentiality Notice

The information contained in this electronic message and any attachments to this 
message are intended
for the exclusive use of the addressee(s) and may contain confidential or privileged 
information. If
you are not the intended recipient, please notify the sender at Wipro or [EMAIL 
PROTECTED] immediately
and destroy all copies of this message and any attachments.

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Re: [Socket Programming]: Need info for Client / Server scenario

2004-05-31 Thread James Edward Gray II
On May 30, 2004, at 11:06 PM, <[EMAIL PROTECTED]> wrote:
Hi,
Howdy.
I need some good links for understanding socket programming (Client /
Server programming).
Not a link specifically, but I feel I would be letting you down if I 
didn't mention Network Programming with Perl.  That is an excellent 
book that covers exactly what you're after and much more.  I strongly 
recommend it.

I have written some scripts for multiple clients and a server (Forking
Server).
But I am facing some problems - the server data has to be shared among
all the child processes - does this happen when we fork - what should I
do for this to happen.
There are basically three major approaches to these kinds of servers:  
Forking, Threaded, and Non-Blocking IO.  As others have mentioned, 
Forking is probably not the way to go in this instance.  You want one 
of the other two.

A Threaded server is the easier of the two to write.  Unfortunately, 
it's still plenty involved so I do suggest referencing to book I 
mentioned above.

Another option you might want to look into is POE, which will probably 
greatly simplify this kind of thing.  It have a learning curve you 
would need to pass too, but can be useful in many applications.  
Unfortunately, this option isn't covered by the Networking book, so 
you'll have to use the POE documentation, if you go this way.

Good luck.
James
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: [Socket Programming]: Need info for Client / Server scenario

2004-05-30 Thread LRMK
This is a pritty involved field for me.

In perl FORKING will create a copy of memory of the existing thread so Data
sharing within the program is not posible
All the veriables are local to the thread.

To share data the stratagy I used is as follows.

The master thread or the data producer updates a database while all the
other threads are fetching data from that database.

Delays of responding client is one problem that I faced when using Forks in
Multy threaded servers in Windows Platform so far I have not been able to
fix that problem.

But you can use a different approach to give information to clients.
Why don't you use a web server as a server and write a CGI program to give
information to your child clients, the CGI will query the DB and give the
data to clients.

or The Master server can update a file (Text) insted of updating the
database, which can be directly accessable through the web server.
So each time the clients need data it download the file from the web server.

Even the master server can be written as a CGI program in a web server so
the master client simply post the data to its URL.

I think it is always a good Idear to avoid writing your own servers specialy
when there is a option.


Rakhitha Karunarathne
Web Master
www.Ad-Man.tk - Free Unlimited Banner Rotators




- Original Message - 
From: <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Monday, May 31, 2004 10:06 AM
Subject: [Socket Programming]: Need info for Client / Server scenario


Hi,



I need some good links for understanding socket programming (Client /
Server programming).

I have written some scripts for multiple clients and a server (Forking
Server).

But I am facing some problems - the server data has to be shared among
all the child processes - does this happen when we fork - what should I
do for this to happen.



Requirement is:

"Normal clients" keep polling the server for some info.

Server will get some info from a "master client" till then the server
responds back with null info to the "Normal clients".

The server data that my master client is updating should get reflected
in all the child processes (of forked server) - this is not happening.
What should I do to achieve this?

Also I want my server to respond back immediately to all the clients
getting connected. This is not happening.



Kindly help me in solving the problem.



Following are the code snippets for clients and server:

Server  Code Snippet:

my $MySocket = new IO::Socket::INET(

   LocalHost => $hostname,

   LocalPort => 7890,

   Proto => 'tcp',

   Listen=> SOMAXCONN,

   Reuse => 1);



$MySocket or die "Error: no socket :$!";



STDOUT->autoflush(1);



print "Server Program Started\n";

print "Waiting ...\n";



while ($client_sock = $MySocket->accept())

{

  # execute a fork, if this is

  # the parent, its work is done,

  # go straight to continue

  next if $kid = fork;

  die "fork: $!\n" unless defined $kid;

  # child now...

  # close the server - not needed

  close $MySocket;

  STDOUT->autoflush(1);

  print "\nACCEPTED: New Client\n";

  while (defined($buf = <$client_sock>))

  {

chomp ($buf);

print "Recievied: $buf\n";

if ($buf =~ / NORMAL_CLIENT/i)

{

  ... # return NULL if $val is NULL

  # else return proper value

$buf = $val;

}

elsif ($buf =~ /MASTER_CLIENT/)

{

  ... # read the info

   # update the variable $val if not NULL

$val = <$client_sock>; (SERVER DATA)

chomp $val;

if ($val ne '')

{

$buf = "SUCCESS";

  }

  else

  {

   $buf = "FAILURE";

}

}

#send msg to client

print $client_sock "$buf\n";



}

exit;

}

continue

{

  close $client_sock;

}



Normal Client Code Snippet:

while ($TRUE)

{

  $MySocket = new IO::Socket::INET(

  PeerAddr => $ServerName,

  PeerPort => $port,

  Proto=> 'tcp');

  if (!$MySocket)

  {

print "Failed to Connect to Server: $ServerName\n";

print "Trying to connect again after 10 seconds\n";

sleep (10);

next;

  }

  else

  {

last;

  }

}



print "Connected to \n";

print "Processing ...\n";



while ($TRUE)

{

print $MySocket "NORMAL_CLIENT_"."$host\n";

$Message = <$MySocket>;

chomp $Message;



if ($Message eq ''})

{

  print "NULL Msg from Server. Polling after (time in seconds):
",$TIME_DELAY * $ONE_MINUTE,"\n";

  sleep ($TIME_DELAY * $ONE_MINUTE );

}


Re: [Socket Programming]: Need info for Client / Server scenario

2004-05-30 Thread Andrew Gaffney
[EMAIL PROTECTED] wrote:
I need some good links for understanding socket programming (Client /
Server programming).
I have written some scripts for multiple clients and a server (Forking
Server). 

But I am facing some problems - the server data has to be shared among
all the child processes - does this happen when we fork - what should I
do for this to happen.
Requirement is: 

"Normal clients" keep polling the server for some info.
Server will get some info from a "master client" till then the server
responds back with null info to the "Normal clients".
The server data that my master client is updating should get reflected
in all the child processes (of forked server) - this is not happening.
What should I do to achieve this?
Also I want my server to respond back immediately to all the clients
getting connected. This is not happening.
Warning: the following is coming from someone who has never written any programs 
with multi-connection servers, forking, or threads, but I have done lots of 
reading ;)

It seems to me that it would work better in your situation to start separate 
threads instead of forking in your program. It would allow you to easily have a 
shared memory space, and I believe threads aren't quite as "expensive" as new 
processes (forking).

Again, keep in mind that you should take anything I say with a grain of salt. 
Anything I say in this thread should be assumed wrong until verified by someone 
who has some idea what they are talking about :)

--
Andrew Gaffney
Network Administrator
Skyline Aeronautics, LLC.
636-357-1548
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



[Socket Programming]: Need info for Client / Server scenario

2004-05-30 Thread suresh.pasupula
Hi, 

 

I need some good links for understanding socket programming (Client /
Server programming).

I have written some scripts for multiple clients and a server (Forking
Server). 

But I am facing some problems - the server data has to be shared among
all the child processes - does this happen when we fork - what should I
do for this to happen.

 

Requirement is: 

"Normal clients" keep polling the server for some info.

Server will get some info from a "master client" till then the server
responds back with null info to the "Normal clients".

The server data that my master client is updating should get reflected
in all the child processes (of forked server) - this is not happening.
What should I do to achieve this?

Also I want my server to respond back immediately to all the clients
getting connected. This is not happening.

 

Kindly help me in solving the problem.

 

Following are the code snippets for clients and server:

Server  Code Snippet:

my $MySocket = new IO::Socket::INET(

   LocalHost => $hostname,

   LocalPort => 7890,

   Proto => 'tcp',

   Listen=> SOMAXCONN,

   Reuse => 1);

 

$MySocket or die "Error: no socket :$!";

 

STDOUT->autoflush(1);

 

print "Server Program Started\n";

print "Waiting ...\n";

 

while ($client_sock = $MySocket->accept())

{

  # execute a fork, if this is

  # the parent, its work is done,

  # go straight to continue

  next if $kid = fork;

  die "fork: $!\n" unless defined $kid;

  # child now...

  # close the server - not needed

  close $MySocket;

  STDOUT->autoflush(1);

  print "\nACCEPTED: New Client\n";

  while (defined($buf = <$client_sock>))

  {

chomp ($buf);

print "Recievied: $buf\n";

if ($buf =~ / NORMAL_CLIENT/i)

{

  ... # return NULL if $val is NULL

  # else return proper value

$buf = $val; 

}

elsif ($buf =~ /MASTER_CLIENT/)

{

  ... # read the info

   # update the variable $val if not NULL

$val = <$client_sock>; (SERVER DATA)

chomp $val;

if ($val ne '')

{

$buf = "SUCCESS";

  }

  else

  {

   $buf = "FAILURE";

}

}

#send msg to client

print $client_sock "$buf\n";



}

exit;

}

continue 

{

  close $client_sock;

} 

 

Normal Client Code Snippet:

while ($TRUE)

{

  $MySocket = new IO::Socket::INET(

  PeerAddr => $ServerName,

  PeerPort => $port,

  Proto=> 'tcp');

  if (!$MySocket)

  {

print "Failed to Connect to Server: $ServerName\n";

print "Trying to connect again after 10 seconds\n";

sleep (10);

next;

  }

  else

  {

last;

  }

}

 

print "Connected to \n";

print "Processing ...\n";

 

while ($TRUE)

{

print $MySocket "NORMAL_CLIENT_"."$host\n";

$Message = <$MySocket>;

chomp $Message;

 

if ($Message eq ''})

{

  print "NULL Msg from Server. Polling after (time in seconds):
",$TIME_DELAY * $ONE_MINUTE,"\n";

  sleep ($TIME_DELAY * $ONE_MINUTE );

}

else

{

print "Msg from Server: $Message\n";

}

}#end of while

close $MySocket;

 

 

Master Client Code Snippet:

while ($TRUE)

{

  $MySocket = new IO::Socket::INET(

  PeerAddr => $ServerName,

  PeerPort => $port,

  Proto=> 'tcp');

  if (!$MySocket)

  {

print "Failed to Connect to Server: $ServerName\n";

print "Trying to connect again after 10 seconds\n";

sleep (10);

next;

  }

  else

  {

last;

  }

}

 

print "Connected to \n";

print "Processing ...\n";

 

print $MySocket "MASTER_CLIENT_"."$host\n";

print $MySocket "$Information\n"; #this msg has to be sent to Server
where all other Normal clients are waiting for this info

$Message = <$MySocket>;

chomp $Message;

print "Msg from Server: $Message\n";

 

close $MySocket;

 

Thanks in advance 

Suresh