Client3 needs to verify client1 and client2. client 4 needs to verify all client1,2 and 3s..

How many clients are there?

Say there were 10. The tenth client has to check 9 md5s and produce one. But who'd check that one?

And why, if two clients have already checked the MD5 of a file and concurred, do you expect that a third client would suddenly produce a different result?

And, presumably the server can also access these files--else how does it randomly pick from them for the clients to operate upon? In which case, why not have the server pick a dozen of so files at random--calculate and store the MD5s--and then supply the entire list of files & md5s to each connecting client for verification. The only response required then is yes or no. Ie:

clients are on different machines, how could the code fit in 20 lines

Well, that was for the server; the client would be about the same again. Eg.

Server:

#! perl -sw use strict; use threads; use threads::shared; use IO::Socket; use Digest::MD5 qw[ md5_hex ]; use List::Util qw[ shuffle ]; use constant CRLF => chr( 13 ) . chr( 10 ); $/ = $\ = CRLF; my %files :shared = map{ open my $fh, '<:raw', $_ or warn "$_: $!"; $_ => md5_hex( do{ local $/; <$fh> } ); } (shuffle glob '*.pl' )[ 0 .. 9 ]; my $server = IO::Socket::INET->new( LocalHost => 'localhost', LocalPort => 1234, Listen => SOMAXCONN, +Reuse =>1, ) or die "Couldn't create listening socket"; while( 1 ) { my $client = $server->accept; async { my $peerhost = $client->peerhost .':'. $client->peerport; print $client join ' ', %files; my $reply = <$client>; print $client 'DONE'; warn "$peerhost : $reply\n"; }->detach; } close $server; __END__ c:\test>850473-s.pl 127.0.0.1:59137 : PASSED 127.0.0.1:59138 : PASSED 127.0.0.1:59139 : PASSED 127.0.0.1:59140 : PASSED 127.0.0.1:59141 : PASSED 127.0.0.1:59142 : PASSED 127.0.0.1:59143 : PASSED 127.0.0.1:59144 : PASSED 127.0.0.1:59145 : PASSED 127.0.0.1:59146 : PASSED 127.0.0.1:59147 : PASSED 127.0.0.1:59148 : PASSED 127.0.0.1:59149 : PASSED 127.0.0.1:59150 : PASSED 127.0.0.1:59151 : PASSED

Client:

#! perl -sw use strict; use Digest::MD5 qw[ md5_hex ]; use IO::Socket; $/ = $\ = chr( 13 ) . chr( 10 ); my $server = IO::Socket::INET->new( 'localhost:1234' ) or die $^E; my %files= split ' ', <$server>; my $result = 'PASSED'; for my $file ( keys %files ) { open my $fh, '<:raw', $file or warn "$_ : $!"; my $md5 = md5_hex( do{ local $/; <$fh> } ); warn "$file: $md5 eq $files{ $file }\n"; next if $md5 eq $files{ $file }; $result = 'FAILED'; last; } printf $server "$result\cM\cJ"; print scalar <$server>; close $server; __END__ junk67.pl: c9c8f25e0d4263a253f45d63b18fb062 eq c9c8f25e0d4263a253f45d6 +3b18fb062 CPtest.pl: 103017b3f98578db15060a31316087e7 eq 103017b3f98578db15060a3 +1316087e7 junk2.pl: 5367ddba375163542c7197bfa355be88 eq 5367ddba375163542c7197bf +a355be88 789655-2.pl: c6b1a7367b57bba6ae0e4556aeb1053c eq c6b1a7367b57bba6ae0e4 +556aeb1053c burnCPU.pl: 0e8afcf32f03fa9382b1bce9b8a5646b eq 0e8afcf32f03fa9382b1bc +e9b8a5646b 815861.pl: cb37349c218e9cd6d4017dc32e436d72 eq cb37349c218e9cd6d4017dc +32e436d72 junk33.pl: c298090e1bc7f8ec599c3b9bff08598e eq c298090e1bc7f8ec599c3b9 +bff08598e MovingAves.pl: 98f1b81b1d9ee099b937982320a1f347 eq 98f1b81b1d9ee099b93 +7982320a1f347 797136-b.pl: 02152b03bb0766e141da67739161f192 eq 02152b03bb0766e141da6 +7739161f192 junk67.pl: c9c8f25e0d4263a253f45d63b18fb062 eq c9c8f25e0d4263a253f45d6 +3b18fb062 817762verify.pl: f0a6b204112d7d8aa7df99e307890705 eq f0a6b204112d7d8aa +7df99e307890705 CPtest.pl: 103017b3f98578db15060a31316087e7 eq 103017b3f98578db15060a3 +1316087e7 DONE

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
RIP an inspiration; A true Folk's Guy

In reply to Re^3: Single server-multiple clients by BrowserUk
in thread Single server-multiple clients by hari9

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.