toadi has asked for the wisdom of the Perl Monks concerning the following question:
Server-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")
So as you see when there's a connect from a client, I need to start another proces.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; }
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
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: UDP and IO::Socket
by toadi (Chaplain) on Jan 15, 2002 at 16:17 UTC |