This post originated from an RSS feed registered with Ruby Buzz
by Red Handed.
Original Post: Revisiting the File-Sharing Paragraph
Feed Title: RedHanded
Feed URL: http://redhanded.hobix.com/index.xml
Feed Description: sneaking Ruby through the system
RedHanded is just over a year old, designed as an exercise to help me flesh out some better code examples and to horse around with dodgy Ruby ideas that perhaps weren’t destined to be full projects. At the time, in December of last year, Florian Gross and Mauricio Fernandez had been golfing with a number of tantalizing scripts like flgr’s 6-line p2p and batsman’s 5-line wiki.
For a while, I ran flgr’s file-sharing app to distribute songs from a Ruby mixtape (day 1, day 2, day 3.) Sadly, the little server didn’t really have concurrency. The project got pocketed.
Lately, I’ve been playing with a rewrite of miniature file-sharing and I really like what’s come out:
This little client/server is patterned after uP2P. It shares everything under the working directory. And, if you can spot the case statement, there are five commands. If you run a single server and telnet into it, you can try these out:
s recursively searches for a glob. s|foobar|*.rb
g reads a file’s contents. g|foobar|p2p.rb
a announces your peer. a|foobar|192.168.0.5:2006
d lists the peer directory. d|foobar|192.168.0.5:2006.
l lists the files for the connected peer only. l|foobar|*.rb
The client mode just downloads from all peers anything matching the glob. I probably need to do some exception handling at some point. This will stream IO, though!