tags:

views:

63

answers:

2

I'm having trouble finding a clear answer to this question so I thought I'd ask here with my own specific example:

I am creating a mulitplayer monopoly game. The actual monopoly code runs on the server and the client is essentially a GUI which accesses and control this code. The monopoly game is controlled by a class called 'Bank'.

Say I did this in the main() of my client:

Bank banker = server.getBank(); //gets the bank object from server
bank.turn(); //moves the current player

Would this call turn() on the Bank object on the server or on a copy of it on my local machine?

Update: Bank does not implement remote. It is a serializable object.

+3  A: 

That depends if Bank is an instance of Remote or not. If so, then it will be passed by reference (if all is set up correctly), if not it'll be serialized and passed by value.

edit: Since your Bank class is not Remote, but is Serializable, then it will be copied and passed by value.

skaffman
It must also be exported though.
PartlyCloudy
@PartlyCloudy: Yes indeed
skaffman
Right so I need to make Bank implement Remote to be able to call methods on it remotely?
Oetzi
@Oetzi: It needs to be `Remote`, it needs to conform to the conventions required by `Remote`, and it needs to be exported. This is all described in the "Passing Objects" section in http://java.sun.com/docs/books/tutorial/rmi/implementing.html
skaffman
I really need to talk to someone face to face about this. Every example I look at only accounts for the client manipulating one class's methods on the server side, where as I have many different classes (Properties, Players etc). Does this mean every class I use must implement Remote?Sorry if this is stupid, I'm just having trouble getting my head around all this.
Oetzi
@Oetzi: The tutorial (see above link) is good. Read it.
skaffman
@Skaffman. Ahhhh I've got it now. My confusion seems to be coming from the fact that my old Java textbook teaches RMI using stubs and skeletons where as it is done differently now. Thank very muh :)
Oetzi
A: 

That depends on how you coded it.

Typically any client side objects that represent server side objects simply make remote calls with update the server side objects. The client side objects are nothing more than a facade over the transport protocols used to make the calls to the server.

If you used RMI, then it will follow this principle.

Robin