Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS 

Introduction to Distributed Ruby

This code demonstrates a client server architecture. I executed the file simple_service.rb on my Ubuntu server (Donatello - 192.168.1.10), then from the CLI output I copied the server uri into the clipboard. I then executed the simple_client.rb on my Ubuntu desktop (Cryton - 192.168.1.3) while passing in the uri as an argument.
#!/usr/bin/env ruby -w
# simple_service.rb
# A simple DRb service

# load DRb
require 'drb'

# start up the DRb service
DRb.start_service nil, []

# We need the uri of the service to connect a client
puts DRb.uri

# wait for the DRb service to finish before exiting
DRb.thread.join

output: druby://donatello.mydomain.com:47159

#!/usr/bin/env ruby -w
# simple_client.rb
# A simple DRb client

require 'drb'

DRb.start_service

# attach to the DRb server via a URI given on the command line
remote_array = DRbObject.new nil, ARGV.shift

puts remote_array.size

remote_array << 1

puts remote_array.size


from the command line
> ./simple_client.rb druby://192.168.1.10:47159


output:
0
1


Note: I substituted the domain name with the ip address because the name in question was not stored within the DNS settings.

Reference: Introduction to Distributed Ruby (DRb) [segment7.net]
« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS