DISPLAY A STRING USING CORBA
By karthick
, in
DISPLAY A STRING USING CORBA
,
0 Comments
Idl file
module
HelloApp
{
interface
Hello
{
string sayHello();
};
};
Implementation file
import
HelloApp.*;
import
org.omg.CORBA.*;
import
org.omg.PortableServer.*;
import
org.omg.PortableServer.POA.*;
class
Helloimpl extends HelloPOA
{
private
ORB orb;
public
Helloimpl()
{}
public
String sayHello()
{
return
"Say Hello";
}
public
void setORB(ORB orb_val)
{
orb=orb_val;
}}
Server file
import
HelloApp.*;
import
org.omg.CORBA.*;
import
org.omg.PortableServer.*;
import
org.omg.PortableServer.POA.*;
import
org.omg.CosNaming.*;
import
org.omg.CosNaming.NamingContextPackage.*;
public
class HelloServer
{
public
static void main(String args[])
{
try
{
ORB
orb=ORB.init(args,null);
POA
rootpoa=POAHelper.narrow(orb.resolve_initial_references("RootPOA"));
rootpoa.the_POAManager().activate();
Helloimpl
helloref=new Helloimpl();
helloref.setORB(orb);
org.omg.CORBA.Object
ref=rootpoa.servant_to_reference(helloref);
Hello
href=HelloHelper.narrow(ref);
org.omg.CORBA.Object
obref=orb.resolve_initial_references("NameService");
NamingContext
ncref=NamingContextHelper.narrow(obref);
NameComponent
nc=new NameComponent("Hello","");
NameComponent
path[]={nc};
ncref.rebind(path,href);
java.lang.Object
sync=new java.lang.Object();
synchronized(sync)
{
sync.wait();
}
}
catch(Exception
e)
{
System.out.println(""+e);
e.printStackTrace(System.out);
}
}
}
Client file
import
HelloApp.*;
import
org.omg.CORBA.*;
import
org.omg.CosNaming.*;
import
java.io.*;
public
class HelloClient
{
public
static void main(String args[])
{
try
{
ORB orb=ORB.init(args,null);
org.omg.CORBA.Object
obref=orb.resolve_initial_references("NameService");
NamingContext
ncref = NamingContextHelper.narrow(obref);
NameComponent
nc=new NameComponent("Hello","");
NameComponent
path[]={nc};
Hello
href=HelloHelper.narrow(ncref.resolve(path));
String
H=href.sayHello();
System.out.println("Hello
world");
}
catch(Exception
e)
{
System.out.println("error"+e);
e.printStackTrace(System.out);
}
}
}
Compilation
D:\11ca013(karthi)\mware\middleware
lab\CORBA1>idlj -fall Hello.idl
D:\11ca013(karthi)\mware\middleware
lab\CORBA1>cd HelloApp
D:\11ca013(karthi)\mware\middleware
lab\CORBA1\HelloApp>path.bat
D:\11ca013(karthi)\mware\middleware
lab\CORBA1\HelloApp>set path=C:\Program File
s\Java\jdk1.6.0\bin
D:\11ca013(karthi)\mware\middleware
lab\CORBA1\HelloApp>javac *.java
Note:
HelloPOA.java uses unchecked or unsafe operations.
Note:
Recompile with -Xlint:unchecked for details.
D:\11ca013(karthi)\mware\middleware
lab\CORBA1\HelloApp>cd..
D:\11ca013(karthi)\mware\middleware
lab\CORBA1>javac *.java
D:\11ca013(karthi)\mware\middleware
lab\CORBA1>tnameserv
Initial
Naming Context:
IOR:000000000000002b49444c3a6f6d672e6f72672f436f734e616d696e672f4e616d696e67436f
6e746578744578743a312e30000000000001000000000000009a000102000000000e3139322e3136
382e312e32303200038400000045afabcb0000000020000f42400000000100000000000000020000
0008526f6f74504f41000000000d544e616d65536572766963650000000000000008000000010000
00011400000000000002000000010000002000000000000100010000000205010001000100200001
0109000000010001010000000026000000020002
TransientNameServer:
setting port for initial object references to: 900
Ready.
Open new window
D:\11ca013(karthi)\mware\middleware
lab\CORBA1>java HelloServer
Open new window
D:\11ca013(karthi)\mware\middleware
lab\CORBA1>java HelloClient 192.168.1.202
Hello
world
D:\11ca013(karthi)\mware\middleware
lab\CORBA1>
0 Response to "DISPLAY A STRING USING CORBA"
Post a Comment