rmi最初级问题

04-09-02 westoreys
我看了thinking in java 2nd 之后,想用它上面的例子演示一下结果,可是不能程序运行,当我运行服务器端的程序时,会出现下面的错误,好像是说访问被拒绝了,我在win2000和winxp上都试过了,错误结果一样,不知但什么原因,下面是错误提示和我的代码,请各位指点。

C:\java>java c15.rmi.PerfectTime

Exception in thread "main" java.security.AccessControlException: access denied (

java.net.SocketPermission 127.0.0.1:1099 connect,resolve)

at java.security.AccessControlContext.checkPermission(AccessControlConte

xt.java:270)

at java.security.AccessController.checkPermission(AccessController.java:

401)

at java.lang.SecurityManager.checkPermission(SecurityManager.java:542)

at java.lang.SecurityManager.checkConnect(SecurityManager.java:1044)

at java.net.Socket.connect(Socket.java:420)

at java.net.Socket.connect(Socket.java:376)

at java.net.Socket.<init>(Socket.java:291)

at java.net.Socket.<init>(Socket.java:119)

at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirect

SocketFactory.java:22)

at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(RMIMaster

SocketFactory.java:128)

at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:562)

at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:185

)

at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:171)

at sun.rmi.server.UnicastRef.newCall(UnicastRef.java:313)

at sun.rmi.registry.RegistryImpl_Stub.bind(Unknown Source)

at java.rmi.Naming.bind(Naming.java:111)

at c15.rmi.PerfectTime.main(PerfectTime.java:23)

代码:

package c15.rmi;

import java.rmi.*;

import java.rmi.server.*;

import java.rmi.registry.*;

import java.net.*;

public class PerfectTime extends UnicastRemoteObject implements PerfectTimeI

{

public long getPerfectTime() throws RemoteException

{

return System.currentTimeMillis();

}

public PerfectTime() throws RemoteException

{}

public static void main(String[] args) throws Exception

{

System.setSecurityManager(new RMISecurityManager());

LocateRegistry.createRegistry(1099);

PerfectTime pt = new PerfectTime();

Naming.bind("PerfectTime",pt);

System.out.println("Ready to do time");

}

}

banq
2004-09-04 17:50
需要配置安全策略文件。

RMI很少在实践中使用,不必研究太多,EJB已经封装了RMI。

最近看到程序员杂志在比较RMI和.NET类似一个技术,我暗自窃笑,RMI在实践中几乎用不到,再好再坏也无实用价值啊。

westoreys
2004-09-16 16:45
多谢,知道了

james5
2004-09-22 13:28
配置一下

这个文件

JAVA_HOME/jre/lib/security/java.policy

猜你喜欢