RMI Server-initiated calls to client methods?

Discussion in 'Java' started by Starwynd, Jan 22, 2004.

  1. Starwynd

    Starwynd Guest

    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!
    Starwynd, Jan 22, 2004
    #1
    1. Advertising

  2. 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

    "Starwynd" <> wrote in message
    news:...
    > 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!
    Alex Molochnikov, Jan 22, 2004
    #2
    1. Advertising

  3. Starwynd

    Starwynd Guest

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

    Starwynd

    "Alex Molochnikov" <> wrote in message news:<twLPb.211184$JQ1.205646@pd7tw1no>...
    > 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
    >
    > "Starwynd" <> wrote in message
    > news:...
    > > 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!
    Starwynd, Jan 23, 2004
    #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. Dan
    Replies:
    5
    Views:
    2,847
    bruce barker
    Dec 1, 2003
  2. Srinivasa Raghavan Sethuraman
    Replies:
    0
    Views:
    546
    Srinivasa Raghavan Sethuraman
    Jun 30, 2004
  3. Guest
    Replies:
    2
    Views:
    2,006
    Steven Cheng[MSFT]
    Aug 18, 2005
  4. Chris Smith
    Replies:
    4
    Views:
    624
  5. Max
    Replies:
    2
    Views:
    362
    John Saunders
    Mar 14, 2007
Loading...

Share This Page