RMI Server-initiated calls to client methods?

S

Starwynd

Greetings.

I'm currently working on programming a game in Java for fun. This is a
multi-player game with the interface done primarily in AWT, and I have
decided to use RMI for functionality over the network, a virtual
experience sort of thing, that includes weather, and other real-time
phenomenon.

Well, the algorithm to determine the current weather is all done on
the Server, currently. However, I have the weather set on a Swing
timer on the server, so that randomly once every 2-10 hours while
running, it makes a local server-side call to the weather method, and
determines the new weather, which clients can then read, and update
their own weather status.

The weather is expressed, on the client side, as a picture.

My problem is this:

Currently, the picture on the client side that denotes the weather is
set by a client-side method, which retrieves the current weather value
from the server, something to the tune of UpdateWeather().(it needs to
be there on the client to correctly display and process some of the
other GUI data).

The weather timer on the server fires off action events; one of which
is update the weather (and therefore the client's GUI image) whenever
it goes off. But how do I implement this? I can't find a way for the
server to initiate a call to every client to tell it to run its own
WeatherUpdate method to display the correct weather. I have a socket
chat running, so it's easy enough to determine the clients connected,
but I am unsure as to how I have the server initiate a call to each
client to tell it to run its own client-side method and update its own
GUI. Any help is much appreciated!
 
A

Alex Molochnikov

To initiate a call to the client, you will have to implement a callback
mechanism, which makes every client a server in its own right. When the
client establishes a connection to the server, it calls one of the server
remote methods and passes (exports) an object as a parameter. The exported
object will have to extend UnicastRemoteObject; when it is time to update
the client, the server can call a remote method on the exported object
(actually on its stub).

Note that this technique will work as long as there are no firewalls
separating clients from the server. If the firewalls are present, you will
have to negotiate opening of ports with the firewall administrator(s), and
make sure that your server objects are exported on those ports.

HTH

Alex Molochnikov
Gestalt Corporation
www.gestalt.com
 
S

Starwynd

Thanks! That info was incredibly helpful, and I found a site with very
good documentation on how to do this :)

Starwynd
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top