473,287 Members | 1,904 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,287 software developers and data experts.

Forking server

How to create a threaded process in Perl. I need explanation for this
code 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);
Jul 19 '05 #1
1 3083
dw

"SRam" <ak**********@yahoo.com> wrote in message
news:20**************************@posting.google.c om...
How to create a threaded process in Perl. I need explanation for this
code from Advanced Perl Programming....
First of all... you probably should take this over to comp.lang.perl.misc.
People complain that this group doesn't exist, you you may get better
answers over there....

# 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);
I'm guessing that $sock should be $main_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);


Advanced Perl Programming has a short description after the segment of code.
You didn't say what you don't understand: the code, the way a server works,
why the code always died? If you say what you don't understand... maybe you
can get a better answer.

Jul 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Hopeless A | last post by:
We are attempting to fork a php script into a background php script and have the first scrip continue to completion. Is this even possible in the windows version of php? We have used the many code...
0
by: Eric S. Johansson | last post by:
I was working on a filter for postfix and instead of using the "fork a new python process on every message" route, I decided to use the SMTP interface instead and try forking after having started...
0
by: SRam | last post by:
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 $!; ...
2
by: Sophia Cao | last post by:
Hello, I am seeking a python solution for my project. I am trying to implement an architecture where there is a server who receives incoming messages from several clients, then those messages...
3
by: felixfix | last post by:
Hi all, I am just wondering if something is wrong with my program. What it bascially does is to output a fibonacci sequence base on the command-line output. If I give a 5, it will generate the...
3
by: czajnik | last post by:
Hi! I'm quite new to Python development. Can someone advise me a framework useful for building (pre-)forking or threaded TCP servers, other than SocketServer ? I've seen source code of a few...
10
by: qwertycat | last post by:
I'm new to multi-process programming, should one avoid forking children from children of a parent? I'd like to spawn 10 children from the parent and each of those children spawns another 5...
2
by: Gilles Ganault | last post by:
Hello I'd like to rewrite the following Perl script in Python: http://www.voip-info.org/wiki/view/Asterisk+NetCID It seems like the following doesn't actually fork, so Asterisk is stuck...
3
by: Scottman | last post by:
I am writing a server daemon that forks a child for every incoming request. The child process terminates when the client closes the connection. My problem is that I am unsure how to prevent the...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.