# Accessing object from dRuby server

**URL:** <https://www.ruby-forum.com/t/accessing-object-from-druby-server/56051>\
**Category:** Ruby\
**Created:** [March 27, 2006, 6:24pm UTC](https://www.ruby-forum.com/t/accessing-object-from-druby-server/56051 "2006-03-27T18:24:02Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mohammad\_K](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/8e8cbc/32.png) [@Mohammad\_K](https://www.ruby-forum.com/u/Mohammad_K)\
**Post date:** [March 27, 2006, 6:24pm UTC](https://www.ruby-forum.com/t/accessing-object-from-druby-server/56051/1 "2006-03-27T18:24:02Z")

</div>

Here is server code:

#!/usr/bin/env ruby

require ‘drb’

location = “druby://localhost:9000”

class Echo  
def initialize(msg=nil)  
@msg = msg.nil? ? “No message!” : msg  
end

```
def message
    return @msg
end

```

end

class EchoServer  
def initialize  
$stdout.puts “EchoServer Started”  
end

```
def echo(msg=nil)
    echo = Echo.new(msg)
    $stdout.puts "Returning echo and its a class of '#{echo.class}'"
    return echo
end

```

end

begin  
server = EchoServer.new  
DRb.start\_service(location, server)  
DRb.thread.join

rescue Interrupt  
$stdout.puts “Thank you for using EchoServer”

rescue  
raise  
end

And Here is my client code:

#!/usr/bin/env ruby

require ‘drb’

location = “druby://localhost:9000”

DRb.start\_service(nil, nil)  
server = DRbObject.new(nil, location)

begin  
echo = server.echo(“Hello dRuby”)  
puts echo.class

rescue SystemCallError  
$stdout.puts “EchoServer returned SystemCallError”

rescue DRb::DRbConnError  
$stdout.puts “EchoServer down … (DRb::DRbConnError)”

rescue Errno::ECONNREFUSED  
$stdout.puts “EchoServer down … (Errno::ECONNREFUSED)”

rescue  
raise  
end

After execute client script, here is my output at server end:

mkhan@mkhan:~$ ruby echoserver.rb  
EchoServer Started  
Returning echo and its a class of ‘Echo’

and here is the output at client end:  
mkhan@mkhan:~/project/CPCServer$ ruby echoclient.rb  
DRb::DRbUnknown

I was expecting at client end to see ‘Echo’  
What I am doing wrong?  
Any help would be greatly appreciated.

Thanks,  
Mohammad

---

<div class="post-metadata">

**Author:** ![Mohammad\_K](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/8e8cbc/32.png) [@Mohammad\_K](https://www.ruby-forum.com/u/Mohammad_K)\
**Post date:** [March 27, 2006, 6:33pm UTC](https://www.ruby-forum.com/t/accessing-object-from-druby-server/56051/2 "2006-03-27T18:33:36Z")

</div>

nvm… I found the answer from archive… I need to used DRb::UnDumped…  
!!

Mohammad
