Forum: Ruby accessing object from dRuby server

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
8c786b59665b31d9e43da6c5e6315a4d?d=identicon&s=25 Mohammad Khan (Guest)
on 2006-03-27 18:24
(Received via mailing list)
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
8c786b59665b31d9e43da6c5e6315a4d?d=identicon&s=25 Mohammad Khan (Guest)
on 2006-03-27 18:33
(Received via mailing list)
nvm.. I found the answer from archive... I need to used DRb::UnDumped..
!!


Mohammad
This topic is locked and can not be replied to.