当前位置: 技术问答>java相关
关于RMI的问题???
来源: 互联网 发布时间:2015-02-17
本文导语: 我写了一个RMI的程序,编译成功,但运行时出现 java.security.AccessControlException: access denied (java.net.SocketPermission 127.0.0.1:1099 connect,resolve) 错误,怎么搞的? package c15.ptime; import java.rmi.*; public interface PerfectTimeI extends...
我写了一个RMI的程序,编译成功,但运行时出现
java.security.AccessControlException: access denied (java.net.SocketPermission 127.0.0.1:1099 connect,resolve)
错误,怎么搞的?
package c15.ptime;
import java.rmi.*;
public interface PerfectTimeI extends Remote
{
long getPerfectTime() throws RemoteException;
}
package c15.ptime;
import java.rmi.*;
import java.rmi.server.*;
import java.rmi.registry.*;
import java.net.*;
import c15.ptime.*;
class PerfectTime extends UnicastRemoteObject implements PerfectTimeI
{
public long getPerfectTime() throws RemoteException
{
return System.currentTimeMillis();
}
public PerfectTime() throws RemoteException
{
}
public static void main(String[] args)
{
System.setSecurityManager(new RMISecurityManager());
try{
PerfectTime pt=new PerfectTime();
Naming.bind("rmi://127.0.0.1/PerfectTime",pt);
System.out.println("Ready to do time");
}catch(Exception e){
e.printStackTrace();
}
}
}
package c15.ptime;
import java.rmi.*;
import java.rmi.registry.*;
public class DisplayPerfectTime
{
public static void main(String[] args)
{
System.setSecurityManager(new RMISecurityManager());
try{
PerfectTimeI t=(PerfectTimeI)Naming.lookup("rmi://127.0.0.1/PerfectTime");
for(int i=0;i
java.security.AccessControlException: access denied (java.net.SocketPermission 127.0.0.1:1099 connect,resolve)
错误,怎么搞的?
package c15.ptime;
import java.rmi.*;
public interface PerfectTimeI extends Remote
{
long getPerfectTime() throws RemoteException;
}
package c15.ptime;
import java.rmi.*;
import java.rmi.server.*;
import java.rmi.registry.*;
import java.net.*;
import c15.ptime.*;
class PerfectTime extends UnicastRemoteObject implements PerfectTimeI
{
public long getPerfectTime() throws RemoteException
{
return System.currentTimeMillis();
}
public PerfectTime() throws RemoteException
{
}
public static void main(String[] args)
{
System.setSecurityManager(new RMISecurityManager());
try{
PerfectTime pt=new PerfectTime();
Naming.bind("rmi://127.0.0.1/PerfectTime",pt);
System.out.println("Ready to do time");
}catch(Exception e){
e.printStackTrace();
}
}
}
package c15.ptime;
import java.rmi.*;
import java.rmi.registry.*;
public class DisplayPerfectTime
{
public static void main(String[] args)
{
System.setSecurityManager(new RMISecurityManager());
try{
PerfectTimeI t=(PerfectTimeI)Naming.lookup("rmi://127.0.0.1/PerfectTime");
for(int i=0;i