Created
June 28, 2011 14:12
-
-
Save 8th-Light-Blog/1051212 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Blog Title: Rinda 101 | |
Author: Jim Suchy | |
Date: February 11th, 2008 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "rinda/tuplespace" | |
port = 4000 | |
ts = Rinda::TupleSpace.new | |
DRb.start_service("druby://:#{port}", ts) | |
puts "Rinda listening on #{DRb.uri}..." | |
DRb.thread.join |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ ruby server.rb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "rinda/rinda" | |
include Rinda | |
port = 4000 | |
ts = DRbObject.new(nil, "druby://:#{port}") | |
while message = gets | |
begin | |
args = message.split(" ") | |
method = args.shift.to_sym | |
topic = args.shift.to_sym | |
message = args.shift | |
message = nil if message == "nil" | |
tuple = [topic, message] | |
puts ts.send(method, tuple) | |
rescue Exception => e | |
puts e.message | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ ruby client.rb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
write message hello | |
Rinda::TupleEntry:0x4f998 | |
write message world | |
Rinda::TupleEntry:0x4cfa4 | |
read message nil | |
message | |
hello | |
take message nil | |
message | |
hello | |
take message nil | |
message | |
world |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ts.write([:message, "hello"]) => Rinda::TupleEntry:0x4f998 | |
ts.write([:message, "world"]) => Rinda::TupleEntry:0x4cfa4 | |
ts.read([:message, nil]) => "hello" | |
ts.take([:message, nil]) => "hello" | |
ts.take([:message, nil]) => "world" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1) [:message] | |
2) [:message, "hello"] | |
3) [:message, "hello", "world"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment