question DRb class definition share or not share

Discussion in 'Ruby' started by Jack, Oct 11, 2007.

  1. Jack

    Jack Guest

    Just go through ruby cookbook & only tutorial for any DRb stuff. But I
    need help explain below example that I don't understand why DRbUndump
    is not needed. On some of the samples, I see class definition is
    defined in a separate file and was 'require' by both client & server.
    But in this case, the class definition is embedded in server side
    code.

    The below code works. I would think variable 'ro' in client represent
    a proxy. So on the server side, the class definiton probably need to
    include DRbUndump. Can anyone explain to my confusion?

    # client
    require 'drb'
    DRb.start_service
    ro = DRbObject.new(nil, 'druby://localhost:7777')
    print ro.songname

    #server
    #!/usr/local/bin/ruby
    require 'drb'

    class SongNameServer
    def initialize(str)
    @filename = str
    end
    def songname
    f = File.new(@filename)
    return f.readline
    end
    end

    DRb.start_service("druby://localhost:7777", SongNameServer.new("/tmp/
    songname"))
    puts DRb.uri

    DRb.thread.join
    Jack, Oct 11, 2007
    #1
    1. Advertising

  2. Jack

    Eric Hodel Guest

    On Oct 11, 2007, at 08:45 , Jack wrote:

    > Just go through ruby cookbook & only tutorial for any DRb stuff. But I
    > need help explain below example that I don't understand why DRbUndump
    > is not needed. On some of the samples, I see class definition is
    > defined in a separate file and was 'require' by both client & server.
    > But in this case, the class definition is embedded in server side
    > code.
    >
    > The below code works. I would think variable 'ro' in client represent
    > a proxy. So on the server side, the class definiton probably need to
    > include DRbUndump. Can anyone explain to my confusion?


    This is exactly right. DRbUndumped forces the creation of a proxy
    object on the client.

    > # client
    > require 'drb'
    > DRb.start_service
    > ro = DRbObject.new(nil, 'druby://localhost:7777')
    > print ro.songname
    >
    > #server
    > #!/usr/local/bin/ruby
    > require 'drb'
    >
    > class SongNameServer
    > def initialize(str)
    > @filename = str
    > end
    > def songname
    > f = File.new(@filename)
    > return f.readline
    > end
    > end
    >
    > DRb.start_service("druby://localhost:7777", SongNameServer.new("/tmp/
    > songname"))
    > puts DRb.uri
    >
    > DRb.thread.join
    >


    --
    Poor workers blame their tools. Good workers build better tools. The
    best workers get their tools to do the work for them. -- Syndicate Wars
    Eric Hodel, Oct 11, 2007
    #2
    1. Advertising

  3. Jack

    Jack Guest

    On Oct 11, 12:10 pm, Eric Hodel <> wrote:
    > On Oct 11, 2007, at 08:45 , Jack wrote:
    >
    > > Just go through ruby cookbook & only tutorial for any DRb stuff. But I
    > > need help explain below example that I don't understand why DRbUndump
    > > is not needed. On some of the samples, I see class definition is
    > > defined in a separate file and was 'require' by both client & server.
    > > But in this case, the class definition is embedded in server side
    > > code.

    >


    >
    > This is exactly right. DRbUndumped forces the creation of a proxy
    > object on the client.
    >


    Thanks Eric, it is much clear to me now! The recipe 16.10 of ruby
    cookbook include class definition on both client and server that was
    not actually required on client side. From other examples, it is clear
    now when I need it. I think I need to watch out the parameters pass to
    the method.

    Your online tutorial also very helpful, BTW, thanks again!
    Jack, Oct 11, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Saraswati lakki
    Replies:
    0
    Views:
    1,277
    Saraswati lakki
    Jan 6, 2012
  2. Miles Keaton
    Replies:
    3
    Views:
    165
    Miles Keaton
    Mar 30, 2005
  3. Kirk Haines

    More DRb; SSL & DRB & errors

    Kirk Haines, Jul 1, 2005, in forum: Ruby
    Replies:
    0
    Views:
    115
    Kirk Haines
    Jul 1, 2005
  4. J. Wook
    Replies:
    16
    Views:
    267
    Robert Klemme
    May 16, 2007
  5. Ittay Dror
    Replies:
    1
    Views:
    119
    Ittay Dror
    Oct 21, 2008
Loading...

Share This Page