wood burning stoves*
The moose likes Distributed Java and the fly likes Pushing Data from the RMI Server Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Distributed Java
Bookmark "Pushing Data from the RMI Server" Watch "Pushing Data from the RMI Server" New topic
Author

Pushing Data from the RMI Server

Vinodh Sa
Ranch Hand

Joined: May 06, 2010
Posts: 55
Hi All,

I m totally new to RMI. I started learning RMI yesterday only, when i came through the RMI chapter in J2EE Bible.

I m facing one problem when i m using the concept of "Pushing Data from the RMI server".

I m getting the "Access denied" exception in client side when i try to call a method of server side code, inspite of having the security.policy file.

Can anyone help me in this ?

Code:




After starting the rmi registry and the FlightServer2, i m running the flight client2 using the following command

java -Djava.security.policy=security.policy FlightClient2

But i m getting, "Access Denied" exception after abt 30 seconds.....

Any one please help......


Thanks, Vinodh
[Servlet tutorial]
miguel roxo
Greenhorn

Joined: Aug 19, 2011
Posts: 1

hi Vinodh,
why are you exporting the client?
"UnicastRemoteObject.exportObject(fc); " in line 102;

I'm guessing you're trying to do something asynchronous with your RMI app, but to do that you just have to use a callback in the client and pass the reference to the server and it will notify the client when it's done; you can Google more info about callback easily;
But usually RMI works in a direct way:
-client request the server reply an object;

And the server is the one who as to be exported not the client;

You may do one of these:
- if your server extends UnicastRemoteObject, you don't need to export it;
- or else:
server = new ClassServer();
RemoteInterfaceExtendedByServerClass stub=(RemoteInterfaceExtendedByServerClass) UnicastRemoteObject.exportObjct(server);

This code is follows one of the options above.
Registry registry =LocateRegistry.createRegistry(port_where_your_server_will_listen_for_requests);
registry.rebind("the_name_of_the_RMI_service",server);
while(true){
Thread.currentThread();
Thread.sleep(100);
}

Now the server is registed in the service names and binded to a port;

In the client you just have to do this:

RemoteInterfaceExtendedByServerClass client = null;
Registry registry = LocateRegistry.getRegistry("your_server_ip or name, if same machine then localhost",port_where_your_server_will_listen_for_requests);
client = (RemoteInterfaceExtendedByServerClass) registry.lookup(RemoteInterfaceExtendedByServerClass);

and after this you can call any function in your RemoteInterfaceExtendedByServerClass interface;

Regards, hope this helps you.
Miguel Roxo
 
wood burning stoves
 
subject: Pushing Data from the RMI Server
 
Similar Threads
Not able to use two ports in RMI chat application
Implemet rmi Client on an Applet
running a rmi sample
Read a file line by line
jsp vs rmi