|
|
Passing remote objects is akin to passing by reference. The data
are all stored in one place.
-
This is similar to calling the server as we do now. The client receives
a stub, saves that in a variable of the type of the stub's interface, and
calls methods on that variable.
-
Only remote methods can be accessed through the stub.
-
All other methods are local, and can only be accessed where the object
actually resides.
-
Stubs are generated only for remote classes, and they only contain methods
that are in the interface.
-
So let's make a remote class called LoginRoster that maintains a list of
people logged in.
-
This makes sense to be remote, because we want the server to control a
single list of logged in users. If we had multiple copies of this,
one on each client, for instance, they would quickly get out of synch.
-
We'll need to implement our login method as well. We can just pop
up a JOptionPane to prompt the user for a login. We can also have
the BulletinBoard log in.
-
Screen Captures:
-
First, I start the server.
-
Then I start one client and login Brandan.
-
I start the second client and login Conrad McMasters.
Now, I can click on Show Users in etiher client and we'll see
both Brandan and Conrad McMasters logged in.
Pardon the format, I should put each user on a new line. But...
you get the picture.
Also note how a message from each client now appears in the
bulletin board.
Brandan logs off, now we just see Conrad.
The Source
|