CORBA例子(转)————————我也不知道是什麽东东:-)
Below is a simple example of a CORBA programdownload the source file
1. produce a idl file like this
hello.idl
module HelloApp {
interface Hello {
string sayHello();
};
};
2. produce stub and skeleton files through idltojava.exe
idltojava hello.idl
idltojava is not include in the jdk. But you can download it from idldojava.
3. write a server program like this
// HelloServer.java
import HelloApp.*;
import org.omg.CosNaming.*;
import org.omg.CosNaming.NamingContextPackage.*;
import org.omg.CORBA.*;
import java.io.*;
class HelloServant extends _HelloImplBase
{
public String sayHello()
{
return "\nHello world !!\n";
}
}
public class HelloServer {
public static void main(String args[])
{
try{
// create and initialize the ORB
ORB orb = ORB.init(args, null);
// create servant and register it with the ORB
HelloServant helloRef = new HelloServant();
orb.connect(helloRef);
// get the root naming context
org.omg.CORBA.Object objRef =
orb.resolve_initial_references("NameService");
NamingContext ncRef = NamingContextHelper.narrow(objRef);
// bind the Object Reference in Naming
NameComponent nc = new NameComponent("Hello", "");
NameComponent path[] = {nc};
ncRef.rebind(path, helloRef);
// wait for invocations from clients
java.lang.Object sync = new java.lang.Object();
synchronized (sync) {
sync.wait();
}
} catch (Exception e) {
System.err.println("ERROR: " + e);
e.printStackTrace(System.out);
}
}
}
4. write a client program like this
// HelloClient.java
import HelloApp.*;
import org.omg.CosNaming.*;
import org.omg.CORBA.*;
public class HelloClient
{
public static void main(String args[])
{
try{
// create and initialize the ORB
ORB orb = ORB.init(args, null);
// get the root naming context
org.omg.CORBA.Object objRef =
orb.resolve_initial_references("NameService");
NamingContext ncRef = NamingContextHelper.narrow(objRef);
// test
System.out.println("OK..");
// resolve the Object Reference in Naming
NameComponent nc = new NameComponent("Hello", "");
NameComponent path[] = {nc};
Hello helloRef = HelloHelper.narrow(ncRef.resolve(path));
// call the Hello server object and print results
//String oldhello = helloRef.lastMessage();
//System.out.println(oldhello);
String Hello = helloRef.sayHello();
System.out.println(Hello);
} catch (Exception e) {
System.out.println("ERROR : " + e) ;
e.printStackTrace(System.out);
}
}
}
5. complie these files
javac *.java HelloApp/*.java
6. run the application
a. first you@#ve to run the Name Service prior to the others likethis
c:\>tnameserv
b. run server
c:\>java HelloServer
c. run client
c:\>java HelloClient
If you have problems with this example, do let me know!
↓相关文章:
- · 在Windows上安装Tomcat
- · 在Linux上安装Tomcat
- · <试验>win2k在apache1.3上配置tomcat3.1
- · 在windows2000 server中文版上安装apache <原创>
- · EJB概述(上)
- · WebSphere快速入门(15)
- · EJB内部资参1
- · EJB内部资参3
- · JRun常见问题回答 (JRun 中文 FAQ)
- · 真正的apache,tomcat,mod_jk安装指南 原创
- · java bean 与 ejb的区别
- · 将 Microsoft 的 Internet Information Server 用作 Java servlet 引擎 一 (给学过ASP的朋友)
- · j2ee doc 翻译系列之二
- · j2ee的jdbc配置指南(二 ) 连接sql server 数据库
- · ejb一则,franzy@163.net多多交流哦
- · WebSphere快速入门(19)
- · WebSphere快速入门(21)
- · WebSphere快速入门(1)
- · WebSphere快速入门(3)
- · WebSphere快速入门(5)
- · WebSphere快速入门(7)
- · WebSphere快速入门(9)
- · WebSphere快速入门(10)
- · WebSphere快速入门(11)
- · WebSphere快速入门(13)
- · 第三部分:布署和使用 Enterprise JavaBeans 组件(一)(转)
- · 第二部分:EJB 编程模型(转)
- · JavaBean 与 Enterprise JavaBean:有什么不同?(转)
- · 全面研读 EJB 2.0
- · Resin与IIS结合的一些补充技巧
- · 使用JAVA开发CORBA应用
- · WIN2000 下JSP环境的建立(IIS+resin+j2sdk)
- · bea weblgic中介绍的一个jsp调用ejb的好例子,相当详细。
- · jsp与ejb通信 (转)
- · WebSphere快速入门(17)
- · Weblogic中使用Servlet
- · WebLogic6.0中Ejb的使用
- · Tomcat中文手册(1)_转
- · APACHE+TOMCAT+ORACLE安装指南(少爷原创
- · weblogic文档大全(URL)
- · 分布式对话服务器的管理(2)
- · 分布式对话服务器的管理(4)
- · 分布式对话服务器的管理(6)
- · 无状态Enterprise JavaBeans的观点
- · NT下安装JSP

