Eric Hodel
3/1/2007 8:26:00 AM
To start off, don't hijack threads by changing the subject. Start
new threads.
In other words, use the "Reply" button to create a new thread. That
is what the "New" button is for.
On Feb 28, 2007, at 23:42, Raj Sahae wrote:
> I'm going to try to explain this problem without posting huge
> amounts of code, so please stick with me.
>
> Imagine you have an object, GameServer, that contains an instance
> of some object, Game.
> Game has many objects it owns too, Player's, Deck's, Card's, and
> all these objects have methods.
> Then, I start a DRb service, passing in GameServer.game. This
> isn't what the code actually is, but a
> basic skeleton would be something like:
>
> Class GameServer
include DRbUndumped
> def initialize
> @game = Game.new
> end
> end
>
> Class Game
include DRbUndumped
> def initialize
> @players = Array.new #holds Player.new instances
> end
> end
>
> Class Player
include DRbUndumped
> def initialize
> @name
> @hand = Array.new # holds Cards
> @deck = Array.new # holds Cards
> end
>
> def draw
> @hand << @deck.shift
> end
> end
>
> DRb.start service etc etc
>
>
> I have a client that starts a DRb service, creating a DRbObject
> game. I wasn't successfull in using DRbUndumped, so I have all the
> classes defined on both the server and the client(probably related
> to the problem but I can't get DRbUndumped to work).
To write a game server with multiple clients you're going to need to
use DRbUndumped. Without it each client has their own deck, so one
client drawing a card won't affect any other client's decks.
> I know the connection works because I have accessed data through
> the connection, but at some point, the client calls a method on the
> DRbObject, and nothing happens.
Because each client has its own copy of the game.
> It's a Player.draw method, that takes a Card from Deck, and puts it
> in Player.hand. I threw some prints in there, so I know the method
> is being called, but it's not having the desired effect. I want
> the object on the server to change, but apparently the intuitive
> way to go about that isn't the correct way.
Adding DRbUndumped to your classes will fix this.
> When I call the method, the prints show up in the clients prompt.
> How do I activate the method on the server, from the client,
> thereby manipulating the object on the server?
Use DRbUndumped.
> I know that paragraph can be quite confusing. Please ask for
> clarification where needed.
DRbUndumped forces RMI.
Without DRbUndumped each client receives a copy of the object on the
server. Your client is sending messages to the client's object
instead of sending messages to the server's object. With DRbUndumped
there exists the copy on the server and a proxy object on the client
which forwards messages to the server.
Note that DRb is not really client-server, but peer-to-peer, as any
client may also be a server.