By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,742 Members | 2,026 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,742 IT Pros & Developers. It's quick & easy.

Forking Server

P: n/a
I a writing Forking Server for a Small application..

This is code for multiplexing

my $listen = IO::Socket::INET->new(Proto => 'tcp',LocalPort => 2323,
Listen => 1, Reuse => 1)
or die $!;

$listen->autoflush(1);

my $readable_handles = new IO::Select();
$readable_handles->add($listen);
while (1)
{
$listen->autoflush(1);
($new_readable) = IO::Select->select($readable_handles, undef,
undef, 0);

foreach $sock (@$new_readable)
{

if ($sock == $listen)
{
my $new_sock = $sock->accept();
$readable_handles->add($new_sock);
$count++;
$flag = 0;
print $new_sock->fileno . ": connected\n";
}
else
{
$sock->recv($line,300);
print "Received Message\n";
print "Message = $line\n";
......operations....
}
}
}

I also got code for Forking Server from advanced perl programming

# Forking server
use IO::Socket;
$SIG{CHLD} = sub {wait ()};
$main_sock = new IO::Socket::INET (LocalHost => 'goldengate',
LocalPort => 1200,
Listen => 5,
Proto => 'tcp',
Reuse => 1,
);
die "Socket could not be created. Reason: $!\n" unless ($sock);
while ($new_sock = $main_sock->accept()) {
$pid = fork();
die "Cannot fork: $!" unless defined($pid);
if ($pid == 0) {
# Child process
while (defined ($buf = <$new_sock>)) {
# do something with $buf ....
print $new_sock "You said: $buf\n";
}
exit(0); # Child process exits when it is done.
} # else 'tis the parent process, which goes back to accept()
}
close ($main_sock);

I need to convert the multipexing one of first to forking..I don't
know exactly where to modify...Can Anyone help me get me the exact
code...
Jul 19 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.