求救,RMI中绑定出错,急急急,,巨分狂送,不够再加!!!!!!!!!!

凌波微搏 2002-09-26 09:29:48
如能留下Email,或者QQ,就更好。
在运行一个Rmi服务端程序的时候提示绑定出错,下面是打印出来的出错信息,这个程序是一个例程。
java.security.AccessControlException: access denied (java.net.SocketPermission 1
27.0.0.1:10009 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:419)
at java.net.Socket.connect(Socket.java:375)
at java.net.Socket.<init>(Socket.java:290)
at java.net.Socket.<init>(Socket.java:118)
at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirect
SocketFactory.java:22)
at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(RMIMaster
SocketFactory.java:122)
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.rebind(Unknown Source)
at java.rmi.Naming.rebind(Naming.java:159)
at LocalRemoteServer.<init>(LocalRemoteServer.java:81)
at LocalRemoteServer.main(LocalRemoteServer.java:38)

主程序:
/**
* Class: LocalRemoteServer
*
*/

import java.net.*;
import java.io.*;

import java.rmi.*;
import java.rmi.server.*;
import java.rmi.registry.LocateRegistry;

public class LocalRemoteServer
{
private static final int PORT = 10009;

//
// -> Change the name to your own computer name
//
private static final String HOST_NAME = "LocalHost";


// Instance of ourselves
private static LocalRemoteServer lrs;

public static void main
(
String[] args
)
{
// We need to set the security manager to the RMISecurityManager
System.setSecurityManager( new RMISecurityManager() );

try
{
lrs = new LocalRemoteServer();
}
catch ( java.rmi.UnknownHostException uhe )
{
System.out.println( "The host computer name you have specified, " + HOST_NAME + " does not match your real computer name." );

}
catch ( RemoteException re )
{
System.out.println( "Error starting service" );
System.out.println( "" + re );
}
catch ( MalformedURLException mURLe )
{
System.out.println( "Internal error" + mURLe );
}
catch ( NotBoundException nbe )
{
System.out.println( "Not Bound" );
System.out.println( "" + nbe );
}

} // main


// Constructor
public LocalRemoteServer()
throws RemoteException,
MalformedURLException,
NotBoundException
{

LocateRegistry.createRegistry( PORT );

System.out.println( "Registry created on host computer " + HOST_NAME + " on port " + Integer.toString( PORT) );

RemoteModelMgrImpl rmmImpl = new RemoteModelMgrImpl();

System.out.println( "RemoteModelImpl object created" );

String urlString = "//" + HOST_NAME + ":" + Integer.toString( PORT ) + "/" + "RemoteModelManager";
try
{
Naming.rebind( urlString, rmmImpl );
}
catch(Exception e)
{
System.out.println("bind error..............");
e.printStackTrace();

System.exit(0);
}
System.out.println( "Bindings Finished, waiting for client requests." );
}

} // class LocalRemoteServer
...全文
159 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
Kick_hotdog 2002-09-26
  • 打赏
  • 举报
回复
to webwing(中国鹰派):
如何在程序段里指定policy??
比如,policy跟随在我的应用程序所在目录中,
我如何将policy指定到我程序中?
================================================================

CSDN 论坛助手 Ver 1.0 B0402提供下载。 改进了很多,功能完备!

★ 浏览帖子速度极快![建议系统使用ie5.5以上]。 ★ 多种帖子实现界面。
★ 保存帖子到本地[html格式]★ 监视您关注帖子的回复更新。
★ 可以直接发贴、回复帖子★ 采用XML接口,可以一次性显示4页帖子,同时支持自定义每次显示帖子数量。可以浏览历史记录!
★ 支持在线检测程序升级情况,可及时获得程序更新的信息。

★★ 签名 ●
可以在您的每个帖子的后面自动加上一个自己设计的签名哟。

Http://www.ChinaOK.net/csdn/csdn.zip
Http://www.ChinaOK.net/csdn/csdn.rar
Http://www.ChinaOK.net/csdn/csdn.exe [自解压]

webwing 2002-09-26
  • 打赏
  • 举报
回复
权限问题,运行时加上-Djava.security.policy=allPolicy就好了。
allPolicy文件内容如上。
ezyw 2002-09-26
  • 打赏
  • 举报
回复
用这个bat文件
cd classes
set OLDCLASSPATH=%CLASSPATH%
set CLASSPATH=
start rmiregistry
java -Djava.rmi.server.codebase=http://localhost/ -Djava.security.policy=allPolicy 你的类文件
set CLASSPATH=%OLDCLASSPATH%
set OLDCLASSPATH=


其中设置allPolicy文件内容为grant
{
permission java.security.AllPermission;
};
Kick_hotdog 2002-09-26
  • 打赏
  • 举报
回复
//interface
import java.rmi.*;
import java.rmi.server.*;

public interface RemoteModelMgr extends java.rmi.Remote{
public void sayHello()throws RemoteException;
}
//
import java.rmi.server.*;
import java.rmi.*;
import java.io.Serializable;

public class RemoteModelMgrImpl implements RemoteModelMgr,Serializable{

public RemoteModelMgrImpl() {
}
public void sayHello()throws RemoteException{
System.out.println("Say Hello!");
}
}

//
import java.net.*;
import java.io.*;

import java.rmi.*;
import java.rmi.server.*;
import java.rmi.registry.LocateRegistry;

public class LocalRemoteServer
{
private static final int PORT = 10009;

//
// -> Change the name to your own computer name
//
private static final String HOST_NAME = "LocalHost";


// Instance of ourselves
private static LocalRemoteServer lrs;

public static void main(String[] args)
{
// We need to set the security manager to the RMISecurityManager
System.setSecurityManager( new RMISecurityManager() );

try
{
lrs = new LocalRemoteServer();
}
catch ( java.rmi.UnknownHostException uhe )
{
System.out.println( "The host computer name you have specified, " + HOST_NAME + " does not match your real computer name." );

}
catch ( RemoteException re )
{
System.out.println( "Error starting service" );
System.out.println( "" + re );
}
catch ( MalformedURLException mURLe )
{
System.out.println( "Internal error" + mURLe );
}
catch ( NotBoundException nbe )
{
System.out.println( "Not Bound" );
System.out.println( "" + nbe );
}

} // main


// Constructor
public LocalRemoteServer() throws RemoteException, MalformedURLException,NotBoundException
{

LocateRegistry.createRegistry( PORT );

System.out.println( "Registry created on host computer " + HOST_NAME + " on port " + Integer.toString( PORT) );

RemoteModelMgrImpl rmmImpl = new RemoteModelMgrImpl();

System.out.println( "RemoteModelImpl object created" );

String urlString = "//" + HOST_NAME + ":" + Integer.toString( PORT ) + "/" + "RemoteModelManager";
try
{
Naming.rebind( urlString, rmmImpl );
}
catch(Exception e)
{
System.out.println("bind error..............");
e.printStackTrace();

System.exit(0);
}
System.out.println( "Bindings Finished, waiting for client requests." );
}
}
在jdk\jre\security\java.policy中修改
permission java.net.SocketPermission "*:1024-65535", "listen,accept,connect";
运行结果:
Registry created on host computer LocalHost on port 10009
RemoteModelImpl object created
Bindings Finished, waiting for client requests.
================================================================

CSDN 论坛助手 Ver 1.0 B0402提供下载。 改进了很多,功能完备!

★ 浏览帖子速度极快![建议系统使用ie5.5以上]。 ★ 多种帖子实现界面。
★ 保存帖子到本地[html格式]★ 监视您关注帖子的回复更新。
★ 可以直接发贴、回复帖子★ 采用XML接口,可以一次性显示4页帖子,同时支持自定义每次显示帖子数量。可以浏览历史记录!
★ 支持在线检测程序升级情况,可及时获得程序更新的信息。

★★ 签名 ●
可以在您的每个帖子的后面自动加上一个自己设计的签名哟。

Http://www.ChinaOK.net/csdn/csdn.zip
Http://www.ChinaOK.net/csdn/csdn.rar
Http://www.ChinaOK.net/csdn/csdn.
wjmmml 2002-09-26
  • 打赏
  • 举报
回复
给出的错误是访问安全异常,侃侃你是否有权限。
pentax 2002-09-26
  • 打赏
  • 举报
回复
是权限问题,如果你不修改policy策略文件,不允许你打开Socket,找到jdk下的java.policy文件,在其中仿照其他格式将
// allows anyone to listen on un-privileged ports
permission java.net.SocketPermission "localhost:1024-", "listen";
改为:
permission java.net.SocketPermission "*:1024-65535", "listen,accept,connect";

就是允许1024以上的端口监听,接受,连接,如果是在JBuilder下调试,就要修改JBuilder下面的,也可以参照自己写一个,在运行时自己指定policy,命令格式如下:
java -Djava.rmi.server.codebase=http://myhost/~myusrname/myclasses/ -Djava.security.policy=$HOME/mysrc/policy ?examples.hello.HelloImpl

相关连接:
http://java.sun.com/products/jdk/1.2/docs/guide/security/PolicyFiles.html
http://java.sun.com/products/jdk/1.2/docs/guide/security/permissions.html

wjmmml 2002-09-26
  • 打赏
  • 举报
回复
给出的错误是访问安全异常,侃侃你是否有权限。
凌波微搏 2002-09-26
  • 打赏
  • 举报
回复
再顶!!
凌波微搏 2002-09-26
  • 打赏
  • 举报
回复
顶一下!!!!!!!!!
内容概要:本文围绕基于蜣螂优化算法(DBO)的无线传感器网络(WSN)覆盖优化问题展开研究,提出了一种创新性的智能优化解决方案,并提供了完整的Matlab代码实现。研究首先分析了传统WSN覆盖优化存在的覆盖率低、能耗不均等问题,随后引入蜣螂优化算法这一新型群体智能算法,通过模拟蜣螂的生物行为机制,构建了适用于传感器节点部署优化的数学模型。文详细阐述了算法的设计思路、实现步骤及其在提高网络覆盖率、延长网络生命周期方面的有效性,同时通过仿真实验与其他主流优化算法进行了对比,验证了所提方法的优越性。; 适合人群:具备一定优化算法基础和Matlab编程能力,从事通信工程、物联网、智能优化等相关领域的研究生及科研人员。; 使用场景及目标:①解决无线传感器网络节点部署不合理导致的覆盖盲区问题;②提升网络整体覆盖性能与资源利用效率;③为智能优化算法在实际工程的应用提供可复现的研究案例和技术参考。; 阅读建议:建议读者结合文的Matlab代码进行实践操作,重点关注算法参数设置、适应度函数设计及仿真结果分析部分,同时可尝试将该算法迁移至路径规划、资源调度等其他优化场景进行拓展研究。
已经博主授权,源码转载自 https://pan.quark.cn/s/a4b39357ea24 在信息技术领域,特别是软件编程行业,微软公司推出的集成开发环境(IDE)Visual Studio,凭借其卓越的功能和广泛的适用范围,成为了众多程序员的常用工具。不过,在实际操作期间,用户可能会遭遇各种挑战,其一种较为普遍的挑战是“Visual Studio遭遇了异常情况,这或许与某个附加组件有关”。本文将详细研究这一现象的成因、潜在后果以及最终的应对措施。 ### 原因剖析 Visual Studio通过支持多种插件和附加组件来扩展其功能,这些组件通常由第三方开发者设计,旨在为用户提供更多个性化和专业化的工具。然而,这些插件的质量良莠不齐,部分可能未经过充分的测试或与特定版本的Visual Studio存在兼容性难题,从而在执行时引发异常。异常的出现可能源于以下几个因素: 1. **代码缺陷**:若附加组件的代码存在逻辑问题或资源管理不当,就可能导致运行时异常。 2. **资源竞争**:多个插件同时占用相同的资源(例如内存、文件句柄等),可能会产生资源冲突,进而触发异常。 3. **依赖不匹配**:插件可能需要特定版本的库或框架,如果系统安装的版本不一致,也可能导致异常。 4. **安全隐患**:部分插件可能存在安全漏洞,一旦被恶意利用,可能会导致更严重的问题,包括但不限于异常崩溃。 ### 后果分析 当Visual Studio遇到由附加组件引发的异常时,不仅会断当前的工作进程,降低开发效能,还可能带来以下潜在风险: 1. **数据遗失**:若异常发生在保存操作之前,可能会导致未保存的工作内容遗失。 2. **稳定性减弱**:频繁的异常会导致Visual Stud...

62,621

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧