Re: P2P in 15 lines
[email protected] (Vladi Belperchinov-Shabanski)
| Newsgroups | perl.fwp |
|---|---|
| Organization | CSA |
| Message-ID | <[email protected]> |
On Wed, 15 Dec 2004 16:59:35 +0100 Sven Neuhaus <[email protected]> wrote: > Can we beat them (in perl)? > http://www.freedom-to-tinker.com/tinyp2p.html I believe this is not fun :) Using libraries etc ruins the golf scent unless strict description. However without investigating the tinyp2p which lacks description what it exactly does, I came up with those: # pps.pl server--returns file name and data by regexp from current dir #!/usr/bin/perl use IO::Socket::INET; use IO::All; my $sr=$sock = IO::Socket::INET->new(Listen => 5, LocalAddr => 'localhost:9999', ReuseAddr => 1 ); while(4) { my $cl = $sr->accept() or next; $re = <$cl>; chop($re); my @f = grep /$re/, <*>; my $n = shift @f; my $d < io $n; print $cl "$n\n"; print $cl $d; } # 400 bytes approx. and # ppc.pl client--requests file by regexp and save under the server-offered name #!/usr/bin/perl use IO::Socket::INET; use IO::All; my $cl = IO::Socket::INET->new( PeerAddr => "$ARGV[0]:9999") or die "connect error\n"; $| = 1; print $cl "$ARGV[1]\n"; $n = <$cl>; chop($n); $/=undef; <$cl> > io $n; # 200 bytes approx. both are *FAR* from perfect, there are so many issues like security, redirection etc. but still a shot into plain client/server httpd direction :))) P! Vladi. ps: sorry for duplicates, wrong account :/ -- Vladi Belperchinov-Shabanski <[email protected]> <[email protected]> Personal home page at http://cade.datamax.bg/ DataMax SA http://www.datamax.bg there is still one truth on which we can depend we've started something we can never end
pps.pl
(application/octet-stream, 407 B)
#!/usr/bin/perl
use IO::Socket::INET;
use IO::All;
my $sr=$sock = IO::Socket::INET->new(Listen => 5,
LocalAddr => 'localhost:9999',
ReuseAddr => 1 );
while(4)
{
my $cl = $sr->accept() or next;
$re = <$cl>;
chop($re);
my @f = grep /$re/, <*>;
my $n = shift @f;
my $d < io $n;
print $cl "$n\n";
print $cl $d;
}
ppc.pl
(application/octet-stream, 221 B)
#!/usr/bin/perl use IO::Socket::INET; use IO::All; my $cl = IO::Socket::INET->new( PeerAddr => "$ARGV[0]:9999") or die "connect error\n"; $| = 1; print $cl "$ARGV[1]\n"; $n = <$cl>; chop($n); $/=undef; <$cl> > io $n;
signature.asc
(application/pgp-signature, 189 B)
-----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.6 (GNU/Linux) iD8DBQFBwIA6kBm4tG81shQRAgk0AJ4zCMHMOWDODVRaeN5UYBks+6GmhwCfVnbB gvrQINGUci3J/taRh1b9XhE= =qMLP -----END PGP SIGNATURE-----