当前位置: 技术问答>java相关
请问rmi客户端拒绝登陆的问题(附代码,在线等)
来源: 互联网 发布时间:2017-04-10
本文导语: 请问rmi客户端拒绝登陆的问题(附代码) 服务器端: package testforrmi; import java.rmi.*; import java.rmi.Naming; import java.net.*; import java.rmi.server.*; import java.rmi.registry.*; public class sever extends UnicastRemoteObject implements Inte...
请问rmi客户端拒绝登陆的问题(附代码)
服务器端:
package testforrmi;
import java.rmi.*;
import java.rmi.Naming;
import java.net.*;
import java.rmi.server.*;
import java.rmi.registry.*;
public class sever extends UnicastRemoteObject implements Interface1 {
public sever() throws RemoteException{
super() ;
}
public String getname () throws RemoteException{
return "wu" ;
}
public static void main (String args[]){
try {
java.rmi.registry.LocateRegistry.createRegistry(1099) ;
sever s = new sever() ;
Naming.bind("sever",s);
System.out.println("The sever is begin ^^^");
}
catch (Exception ex) {
ex.printStackTrace();
}
}
}
客户端
//////////////////
package testforrmi;
import java.rmi.*;
import java.rmi.registry.*;
public class client {
public client(){
super() ;
}
public static void main(String args[]){
System.setSecurityManager(new RMISecurityManager());
try {
Interface1 inter = (Interface1)Naming.lookup("sever") ;
System.out.println("the test is susses:"+inter.getname());
}
catch (Exception ex) {
ex.printStackTrace();
}
}
}
报错信息:
////
java.security.AccessControlException: access denied (java.net.SocketPermission 10.230.3.254:1099 connect,resolve)
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:272)
at java.security.AccessController.checkPermission(AccessController.java:399)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:545)
at java.lang.SecurityManager.checkConnect(SecurityManager.java:1044)
at java.net.Socket.(Socket.java:262)
at java.net.Socket.(Socket.java:100)
at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirectSocketFactory.java:25)
at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(RMIMasterSocketFactory.java:120)
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:499)
at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:190)
at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:174)
at sun.rmi.server.UnicastRef.newCall(UnicastRef.java:318)
at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
at java.rmi.Naming.lookup(Naming.java:84)
at testforrmi.client.main(client.java:16)
服务器端:
package testforrmi;
import java.rmi.*;
import java.rmi.Naming;
import java.net.*;
import java.rmi.server.*;
import java.rmi.registry.*;
public class sever extends UnicastRemoteObject implements Interface1 {
public sever() throws RemoteException{
super() ;
}
public String getname () throws RemoteException{
return "wu" ;
}
public static void main (String args[]){
try {
java.rmi.registry.LocateRegistry.createRegistry(1099) ;
sever s = new sever() ;
Naming.bind("sever",s);
System.out.println("The sever is begin ^^^");
}
catch (Exception ex) {
ex.printStackTrace();
}
}
}
客户端
//////////////////
package testforrmi;
import java.rmi.*;
import java.rmi.registry.*;
public class client {
public client(){
super() ;
}
public static void main(String args[]){
System.setSecurityManager(new RMISecurityManager());
try {
Interface1 inter = (Interface1)Naming.lookup("sever") ;
System.out.println("the test is susses:"+inter.getname());
}
catch (Exception ex) {
ex.printStackTrace();
}
}
}
报错信息:
////
java.security.AccessControlException: access denied (java.net.SocketPermission 10.230.3.254:1099 connect,resolve)
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:272)
at java.security.AccessController.checkPermission(AccessController.java:399)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:545)
at java.lang.SecurityManager.checkConnect(SecurityManager.java:1044)
at java.net.Socket.(Socket.java:262)
at java.net.Socket.(Socket.java:100)
at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirectSocketFactory.java:25)
at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(RMIMasterSocketFactory.java:120)
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:499)
at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:190)
at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:174)
at sun.rmi.server.UnicastRef.newCall(UnicastRef.java:318)
at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
at java.rmi.Naming.lookup(Naming.java:84)
at testforrmi.client.main(client.java:16)
|
修改policy文件,开放端口权限
|
好像是lib目录下的,自己查找一下java.policy在哪里不就得了
|
我也碰到同样的事情,UP
您可能感兴趣的文章:
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。