双11狂欢大促

盲盒赢 定制羽绒服

开启惊喜盲盒,抽取你的专属好礼

— 惊喜奖品抢先看 —

RMI测试程序都没通过,高手帮看一下!

PiouseLeo PiouseLeo 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
初学RMI,写了如下小程序:
public interface GetTimeI extends Remote {
public abstract long getTime() throws RemoteException;
}

public class GetTimeImpl extends UnicastRemoteObject implements GetTimeI {

private static final long serialVersionUID = 7715100257443541391L;

private String name;

protected GetTimeImpl(String name) throws RemoteException {
super();
this.name = name;
}

public static void main(String[] args) throws Exception {
System.setSecurityManager( new RMISecurityManager());
GetTimeImpl myApp = new GetTimeImpl("GetTime");
System.out.println("rebind........");
Naming.rebind("rmi://127.0.0.1/GetTime", myApp);
System.out.println("Ready!");
}

public long getTime() throws RemoteException{

return System.currentTimeMillis();
}
}

运行时抛出以下异常:
Exception in thread "main" java.security.AccessControlException: access denied (java.net.SocketPermission 192.168.1.100:1099 connect,resolve)
at java.security.AccessControlContext.checkPermission(Unknown Source)
at java.security.AccessController.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkConnect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(Unknown Source)
at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(Unknown Source)
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(Unknown Source)
at sun.rmi.transport.tcp.TCPChannel.createConnection(Unknown Source)
at sun.rmi.transport.tcp.TCPChannel.newConnection(Unknown Source)
at sun.rmi.server.UnicastRef.newCall(Unknown Source)
at sun.rmi.registry.RegistryImpl_Stub.rebind(Unknown Source)
at java.rmi.Naming.rebind(Unknown Source)
at GetTimeImpl.main(GetTimeImpl.java:33)

请问我的程序那里出了问题?
...全文

相关推荐

评论 2
收藏 已收藏
分享
返回顶部
PiouseLeo
Java SE 62,621 成员 307,251 内容