Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

(delete) UDP and IO::Socket

by toadi (Chaplain)
on Jan 15, 2002 at 16:00 UTC ( #138879=perlquestion: print w/ replies, xml ) Need Help??
toadi has asked for the wisdom of the Perl Monks concerning the following question:

my client-script:
use strict; use IO::Socket; my ($host,$port) = ("localhost","9000"); my $remote = IO::Socket::INET->new( Proto => "udp", PeerAddr => $host, PeerPort => $port ) or log_die "cannot connect to $host - $port\n"; die("[Connected to $host:$port]\n"); syswrite($remote, "Yooo\n")
Server-script:
use strict; use IO::Socket; my $socket=IO::Socket::INET->new(LocalAddr => 'localhost', LocalPort => 9000, Proto => 'udp') or die "socket: $!"; my $length; while (defined($length=sysread($socket, my $buffer, 65536)) && $length + != 0) { die "sysread: $!" if (!defined($length)); # When I have a connect from a client start another very big script +:) system('./sleep.pl'); exit; }
So as you see when there's a connect from a client, I need to start another proces.

1) client -> server -> start ./sleep

2) client -> server -> ./sleep still running -> don't wait

3) client -> server -> ./sleep still running -> don't wait

4) client -> server -> sleep not running? start ./sleep

=> for these 2 the server will start sleep 2 times in a row after they are finshed. This I don't want, I want ./sleep only to start when client connects and there is no other sleep running.

For the moment my existing codes makes sure only one ./sleep process is running at a time(thanks to spawning a child and a wait() in the parent). In case 2 and 3 there should never run a ./sleep. only when there is a new connect when there is no ./sleep running.

--
My opinions may have changed,
but not the fact that I am right

Comment on (delete) UDP and IO::Socket
Select or Download Code
Replies are listed 'Best First'.
Re: UDP and IO::Socket
by toadi (Chaplain) on Jan 15, 2002 at 16:17 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://138879]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (13)
As of 2015-07-30 08:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (270 votes), past polls