Link to home
Start Free TrialLog in
Avatar of KABOOM
KABOOM

asked on

My first RMI program my permission problem

I'm writing my very first RMI program and the problem occurs when I run the server.  I get an error saying:
java.net.SocketPermission 127.0.0.1:1099 connect, resolve

How do I fix this?  I read that one possible problem could be the way my computer at home is set up.  I've read some stuff about setting the classpath variable on Windows machines but i'm pretty sure that's not the problem because i've run non-RMI projects on this machine without problems.
I'm running Win2k with Java 2 1.4.x

Here's my code:

import java.rmi.*;
import java.rmi.server.*;

public class SimpleServer extends UnicastRemoteObject implements ServerInterface
{     int matrix1[] = {1, 2, 3, 4, 5};
     int matrix2[] = {6, 7, 8, 9, 10};
     private String ServerName;
     
     SimpleServer(String name) throws RemoteException
     {     super();    
          this.ServerName = name;
     }
     
     public int add() throws RemoteException
     {     System.out.println("Call to add works");
          return 0;
     }

     public int multiply() throws RemoteException
     {     System.out.println("Call to mult works");
          return 0;
     }
     
     public static void main(String args[])
     {     RMISecurityManager SecMgr = new RMISecurityManager();
          System.setSecurityManager(SecMgr);
          try
          {
               SimpleServer myServer = new SimpleServer("FirstRMIServer");
               Naming.rebind("rmi://localhost/FirstRMIServer", myServer);
               System.out.println("RMI Server is registered");
          }
          catch(Exception e)
          {     System.out.println("ERROR: " + e.getMessage());          }    
     }
}
ASKER CERTIFIED SOLUTION
Avatar of vemul
vemul

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of vemul
vemul

check out this site and the SUN RMI site too.. it's got to do with the security file

http://patriot.net/~tvalesky/easyrmi.html

vemul
Avatar of Mick Barry
Do you specify your security policy when you start up the server?
This describes running an RMI server:
http://java.sun.com/docs/books/tutorial/rmi/running.html
Avatar of KABOOM

ASKER

Ok, I read all the articles and tried the security file specified by the link that vemul provided.  The problem is the client says "permission denied" when i've given the AllPermission command in my security policy file.  I thought I might have not closed my server down properly hence I would have two servers listening on the same port but I even went as far as rebooting the machine to make sure but that didn't seem to fix it.

Are there other suggestions?
Later,
KABOOM
can u show us how u start your server, and the contents of your policy file.