BÀI 2 LẬP TRÌNH PHÂN TÁN ĐỐI TƯỢNG CORBA

2.1.5. Bước 5 : Xây dựng chương trình Client File Client.java

import org.omg.CORBA.*;

import org.omg.CosNaming.*;

public class Client{

public static void main(String args[]) throws java.lang.Exception{

//Khoi dong trinh moi gioi ORB

org.omg.CORBA.ORB orb=org.omg.CORBA.ORB.init(args,null);

// Get a reference to the object

org.omg.CORBA.Object nameService=

orb.resolve_initial_references("NameService");

//Chuyen tham chieu ve doi tuong NamingContext

NamingContext nsContext = NamingContextHelper.narrow(nameService);

//tao duong dan mang ten doi tuong

NameComponent nc=new NameComponent("Hello","");

NameComponent path[]={nc};

//Lay ve tham chieu cua doi tuong CORBA tren may chu dua vao ten

Hello corba=HelloHelper.narrow(nsContext.resolve(path));

System.out.println(corba.sayHello() );

}//main

}//class