jacorb Client Server 本地运行 远程调用

来源:互联网 发布:画册制作软件 编辑:程序博客网 时间:2024/05/25 18:11

jacorb Client Server 运行

(1)本地调用

   运行JacORB的ns c:/NS_Ref

这时ns把服务的信息写在了c:/NS_Ref文件里

运行Server和Client

jaco demo.hello.Server

jaco demo.hello.Client

同样,如果后面没有参数,则程序会自动去c:/NS_Ref文件里查找服务信息,然后再运行

 

 

(二)远程调用:

启动ns

在命令行输入dior –f c:/NS_Ref,来解析ior文件,看到ip地址和端口号,将这两个信息写入到java程序中:

org.omg.CORBA.Object ncobj = orb.string_to_object("corbaloc::1.2@192.168.2.203:5545/NameService");

如果写成读取配置文件的形式更方便。

 

修改代码:

将Server中的

NamingContextExt nc = NamingContextExtHelper.narrow(orb
     .resolve_initial_references("NameService"));
  
   nc.bind(nc.to_name("hello.goodDay"), obj); // 绑定对象
改为:

org.omg.CORBA.Object ncobj = orb.string_to_object("corbaloc::1.2@192.168.2.203:5545/NameService");

       NamingContextExt nc = NamingContextExtHelper.narrow(ncobj);

  

   nc.rebind(nc.to_name("hello.goodDay"), obj); // 绑定对象

再将Client中的

NamingContextExt nc = NamingContextExtHelper.narrow(orb
     .resolve_initial_references("NameService"));

改为:

org.omg.CORBA.Object ncobj = orb.string_to_object("corbaloc::1.2@192.168.2.203:5545/NameService");

       NamingContextExt nc = NamingContextExtHelper.narrow(ncobj);

 

 

在服务器断 启动ns 和Server

将Client 部署到另一台电脑上(注:这台电脑也要安装jacorb才可以运行),直接将Client端代码放在这台机子上,运行方法跟本地运行方式一样,可以不用启动ns。