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 4 cases the server will start sleep 4 times in a row . 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


In reply to UDP and IO::Socket by toadi

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.