Forum Stats

  • 3,727,639 Users
  • 2,245,430 Discussions
  • 7,852,905 Comments

Discussions

Prob with starting the RMI Server again

User_AYF65
User_AYF65 Member Posts: 135 Red Ribbon
edited June 2017 in New To Java

Hi,

I ran a rmi program downloaded from a site. It executed yesterday but today I am trying to run the same program from a different folder but I am getting error in the server:

java -Djava.security.poicy=policy HelloServer &

Hello Server failed: java.security.AccessControlException: access denied ("java.net.SocketPermission" "127.0.0.1:1099" "connect,resolve")

My interface code is:

HelloInterface.java

import java.rmi.*;

public interface HelloInterface extends Remote {

  public String say(String m) throws RemoteException;

}

Hello.java

import java.rmi.*;

import java.rmi.server.*;

public class Hello extends UnicastRemoteObject implements HelloInterface {

   private String message; // Strings are serializable

   public Hello (String msg) throws RemoteException {

      message = msg;

   }

   public String say(String m) throws RemoteException {     

      return new StringBuffer(m).reverse().toString()+ "\n" + message;   }}

Compile:

D:\java prog\2017Self\rmi>javac Hello.java

HelloClient.java

import java.rmi.*;

class HelloClient {

   public static void main (String[] args) {

     

      try {

          if(args.length <0){

System.err.println("Usage: java HelloClient string - \n");

             System.exit(1);

          }

          HelloInterface hello = (HelloInterface)Naming.lookup("//localhost/Hello");

         

System.out.println(hello.say(args[1]));       }

          catch (Exception e) {

System.out.println("HelloClient exception: " + e);

          }

    }}

Compile:

D:\java prog\2017Self\rmi>javac HelloClient.java

HelloServer.java

import java.rmi.*;

class HelloServer {

   public static void main (String[] argv) {

if(System.getSecurityManager() == null)

System.setSecurityManager(new SecurityManager());

      try {

Naming.rebind("Hello",new Hello("Hello, world!"));

System.out.println("Hello Server is ready.");      }

      catch (Exception e) {

System.out.println("Hello Server failed: " + e);      } }}

Compile:

D:\java prog\2017Self\rmi>javac HelloServer.java

Policy file

Note the name of this file is policy without any extension. Write the following code on notepad editor and then save as “policy”

grant{

permission java.security.AllPermission;

};

I have also started the rmiregistry but its running from different window despite I wrote “&” after the command:

rmiregistry &

I don’t know why its occupying the command window even when I am using “&” sign.

Is it required to run the rmiregistry and rmi server from the same command window?

Some body please guide me why I am getting security error?

Zulfi.

Best Answer

  • User_AYF65
    User_AYF65 Member Posts: 135 Red Ribbon
    edited June 2017 Accepted Answer

    Hi,

    I shutdown the system and then tried to execute all the things again, this time  server started again. However, when i am running rmiregistry, it occupies the terminal. I dont think & is working.

    Some body please guide,

    Zulfi.

Answers

  • User_AYF65
    User_AYF65 Member Posts: 135 Red Ribbon
    edited June 2017 Accepted Answer

    Hi,

    I shutdown the system and then tried to execute all the things again, this time  server started again. However, when i am running rmiregistry, it occupies the terminal. I dont think & is working.

    Some body please guide,

    Zulfi.

This discussion has been closed.