Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

I missed this post yesterday, as I was deep into writing my own perl P2P app, after someone posted the challenge to the Fun With Perl mailing list. Mine is slightly bigger (717 characters, including newlines), but still 9 lines. I worked under the assumption that any modules in the standard perl distro were fair game (hence IO::Socket)

I tried to emulate the operation of the original python version as closely as possible. I did add one feature that i thought was essential, though: the ability to view files on the network without actually downloading them.

I'm sure better golfers than I could knock this down a bit.

Anyway, mine is used like so:

perl server <passwd> <listenhost:listenport> [<peerhost:peerport>]

perl client <passwd> <serverhost:serverport> list|get <pattern>

Note that when entering a pattern, you need to escape the backslash. So to search for .mp3 files, the pattern would be \\.mp3$

use IO::Socket;($t,$s,$u,$p,$x)=@ARGV;if($t eq"server"){$p&&($p{$p}++, +map{$_ ne $u&&$p{$_}++}f($p,2,$u));while($c=new IO::Socket::INET(LocalAddr=>$u,R +euse=>1, Listen=>9)->accept()){if(<$c>eq"$s\n"){($r=<$c>)>1?do{print$c "$_\n"fo +r keys%p; chomp($a=<$c>);$a&&$p{$a}++;}:do{chomp($x=<$c>);for(grep/$x/,<*>){$z=( +stat)[7]; print$c "$_/$z\n";if($r>0){open G,$_;read G,$b,$z;close;print$c $b}}}} +close$c}} for$v($u,f($u,2,0)){printf"%s (%s)\n",@$_ for f($v,$p eq"get",$x)}sub +f{($h,$q, $m)=@_;$k=new IO::Socket::INET($h)||return;print$k "$s\n$q\n$m",define +d$m?"\n": '';$q>1?chomp(@r=<$k>):do{@r=();while(<$k>){chomp;($f,$e)=split'/';pus +h@r,[$f,$e ]if!$q|!-e$f;next if!$q|-e$f;read$k,$b,$e;open F,">$f";print F$b;close +}};@r}


In reply to Re: P2P Golf: MoleSter by bgreenlee
in thread P2P Golf: MoleSter by hossman

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    [erix]: hm, there's a FANN perl module - looks a bit old
    [Cosmic37]: I'm afraid I don't know the answer to your map question...... what were the references too?
    [corenth]: each reference was to a fairly small scaler.
    [corenth]: I mean, array of scalers. usually triples.
    [Cosmic37]: there is a FANN discussion group but seems to have gone quiet... http://leenissen. dk/fann/forum/ viewforum.php?f=18 &sid=1afc1fb3fa1a3 7f52b03e40d05cdaaa 3

    How do I use this? | Other CB clients
    Other Users?
    Others about the Monastery: (7)
    As of 2018-02-20 18:29 GMT
    Find Nodes?
      Voting Booth?
      When it is dark outside I am happiest to see ...

      Results (274 votes). Check out past polls.