Java Tutorial

 
 
 
 
// 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());    
    }    
}


// Server


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();
        }
    }
}


// Client

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

Z:\\mca317\\corba\\four>java -classpath .\\ GetDateClient -ORBInitialPort 1050 -ORBI
nitialHost mca395
Client Date and Time=Thu Dec 01 16:20:22 IST 2005
Server Date and Time=Thu Dec 01 16:20:16 IST 2005
Time Difference in Server and Client(in millisecond)=5248

    Related Post:
  1. Write a program for restaurant

  2. RMI servlet program to display message

  3. Program to find the number of and sum of all integers greater than 100 and less than 200 that are divisible by 7

  4. An applet program that display blinking rectangle

  5. 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

  6. Program to reverse the number eg given no : - 12345, output want :- 54321

  7. Program to show the use of Increment and Decrement Operators

  8. Program to generate SQUARE ROOT table

  9. Program to show an example of Overriding a Base Class Method

  10. RMI based application for login validation based on data saved in text file stored on the server and will display appropriate message to the client..

  11. Corba program to encrypt the text that you want to send on the client side. The server side decrypts it after receiving. Append server time.

  12. Program to show an example of creating String objects from Character Arrays

  13. Write a program for restaurant

  14. Program that takes a long sentence and a character from the client and count the occurrence of the character in the sentence at the server side

  15. Application which takes your marks of six subjects from the client side and displays the percentage that you have obtained

  16. Corba program of date operations

  17. Create an interface coversions. Which have the following functions Inchestomillimeters(), hptowatts(),wattstohp(),poundstogram(),gramtopounds()

  18. Program to Display Output in triangular shape

  19. Encrypt the text that you want to send on the client side. The server side decrypts it after receiving. Append server time after each word in the sent

  20. Program to calculate the frequency for different values of C starting from 0.01 to 0.1 in steps of 0.01

 
 
Didn't find what you were looking for? Find more on Corba program of date operations