CORBA编程

王朝other·作者佚名  2008-05-19
宽屏版  字体: |||超大  

先编一个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

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
© 2005- 王朝网络 版权所有