Java Blog

 
 
 
// GetDateModule.idl

module GetDateModule
{
    interface GetDate
    {
        string get_date();
        long long get_time();
    };

};


// GetDateImpl
// Contains the implementation of the methods defined in the IDL file.

import GetDateModule.GetDatePOA;
import java.lang.String;
import java.util.Date;

class GetDateImpl extends GetDatePOA
{
    Date dt=new Date();

    GetDateImpl()
    {
        super();
        System.out.println(\"Encriptor Object Created\");
    }

    public String get_date()
    {
        String time=dt.toString();
        return (time);
    }

    public long get_time()
    {
        return(dt.getTime());    
    }    
}


// GetDateServer.java

import GetDateModule.GetDate;
import org.omg.CosNaming.*;
import org.omg.CosNaming.NamingContextPackage.*;
import org.omg.CORBA.*;
import org.omg.PortableServer.*;

class GetDateServer
{

    public static void main(String[] args)
    {
        try
        {
            // initialize the ORB
            org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init(args,null);

            // initialize the BOA/POA
            POA rootPOA = POAHelper.narrow(orb.resolve_initial_references(\"RootPOA\"));
            rootPOA.the_POAManager().activate();

            // creating the GetDate object
            GetDateImpl GetDate = new GetDateImpl();

            // get the object reference from the servant class
            org.omg.CORBA.Object ref = rootPOA.servant_to_reference(GetDate);

            System.out.println(\"Step1\");
            GetDate h_ref = GetDateModule.GetDateHelper.narrow(ref);
            System.out.println(\"Step2\");

            org.omg.CORBA.Object objRef =orb.resolve_initial_references(\"NameService\");

            System.out.println(\"Step3\");
            NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef);
            System.out.println(\"Step4\");

            String name = \"GetDate\";
            NameComponent path[] = ncRef.to_name(name);
            ncRef.rebind(path,h_ref);

            System.out.println(\"GetDate Server reading and waiting....\");
            orb.run();


        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
    }
}


// GetDateClient.java

import GetDateModule.*;
import org.omg.CosNaming.*;
import org.omg.CosNaming.NamingContextPackage.*;
import org.omg.CORBA.*;
import java.io.*;
import java.lang.String;
import java.util.Date;

class GetDateClient
{

    public static void main(String args[])
    {
        GetDate GetDateImpl=null;
        int i;    
        try
        {
            // initialize the ORB
            org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init(args,null);

            org.omg.CORBA.Object objRef = orb.resolve_initial_references(\"NameService\");
            NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef);

            String name = \"GetDate\";
            GetDateImpl = GetDateHelper.narrow(ncRef.resolve_str(name));

            Date dt=new Date();
            long clientTime=dt.getTime();
            System.out.println(\"Client Date and Time=\"+dt);

            String serverDate=(String) GetDateImpl.get_date();

            long serverTime=(long) GetDateImpl.get_time();
            System.out.println(\"Server Date and Time=\"+serverDate);

            System.out.println(\"Time Difference in Server and Client(in millisecond)=\"+(clientTime-serverTime));

        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
    }
}


// OUTPUT

Client Date and Time=Thu Dec 04 16:20:22 IST 2005
Server Date and Time=Thu Dec 04 16:20:16 IST 2005
Time Difference in Server and Client(in millisecond)=5248

    Related Post:
  1. Program to declare and initialize Boolean variables and print them on the Standard Output Device

  2. Program that accepts a shopping list of five items from the command line and stores them in vector

  3. Program to show the use of Switch Statement for the same statement for several different case labels

  4. Program that enabled applet that takes name of the user. Server returns back the number in uppercase clubbed with “HELLO” and display it on applet

  5. Program to search an element in an array using Linear Search

  6. Develop a simple calculator with addition, subtraction, multiplication and division capabilities, data collection from client side, executed on server

  7. Program to show the use of Labeled Continue Statement

  8. Program to show the use of Do-While Loop

  9. Program to show the use of If Statement

  10. An applet program to find maximum of three numbers using textField

  11. Program to show an example of Driving and using a Class

  12. Program to show an example of using a Non-Static Nested Class

  13. Program of linear search

  14. An applet program to perform quick sort

  15. program which takes a long sentence from the client passes to the server,server separates out each word and sends them back to client in reverse order

  16. CORBA based application for addition of two mathematical expressions of the form (ax + by) and displaying the result on client side

  17. Given a list of marks ranging form 0 to 100, write a program to compute and print the number of students marks

  18. Program to determine the sum of the following harmonic series for a given value of n

  19. Develop a game application in CORBA for which the player will guess a number between 1 to 100, which will be compared to the random number generated b

  20. Program to show an example of Concatination of Strings