Chinaunix首页 | 论坛 | 博客
  • 博客访问: 783863
  • 博文数量: 738
  • 博客积分: 7000
  • 博客等级: 少将
  • 技术积分: 5000
  • 用 户 组: 普通用户
  • 注册时间: 2008-09-12 09:00
文章分类

全部博文(738)

文章存档

2011年(1)

2008年(737)

我的朋友

分类:

2008-09-12 09:07:27


  先编一个idl文件,如:person.idl
  module person{
  interface hand{
  int add(int x,int y);
  }
  }
  然后用idl2java.exe文件编译person.idl文件
  idl2java person.idl
  产生一个目录person
  里面有一个文件hand.java,这里定义了一个接口interface hand
  应该编一个类去实现这个接口handImpl.java
  public class handImpl extends _handImplBase implements
  hand{
  int x,y;
  public handImpl(){
  x=0;
  y=0;
  }
  int add(int x,int y){
  this.x=x;
  this.y=y;
  return (x+y);
  }
  }
  总之在handImpl中实现各种功能。
  
  接下来讲端编程:Server.java
  package person;
  public class Server{
  public static void main(String[] argv){
  org.omg.CORBA.ORB
  orb=org.omg.CORBA.ORB.init(args,null);
  org.omg.CORBA.BOA boa=orb.BOA_init();
  person.hand p=new
  person.handImpl("Person.hand");
  boa.obj_is_ready(p);
  System.out.pritnln(p+ " is ready.");
  boa.impl_is_ready();
  }
  }
  如果路径设置对的话,用命令java Server就行了,不过要先运行smart
  agent
  
  public class Client{
  org.omg.CORBA.ORB orb;
  person.hand p;
  public static void main(String[] argv){
  Client app=new Client();
  orb=org.omg.CORBA.ORB.init(args,null);
  
  p=person.handHelper.bind(orb,"Person.hand");
  int result=p.add(20,30);
  System.our.pritnln(result);
  }
  }
  编译用命令javac person\*.java
  
【责编:admin】

--------------------next---------------------

阅读(611) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~