Java Tutorial

 
 
 
 
// encrypt.idl

module encrypt_val
{
  interface encrypt
  {
    string getstr(in string a);
  };
};


// encrypt_client.java

import encrypt_val.*;
import org.omg.CosNaming.*;
import org.omg.CosNaming.NamingContextPackage.*;
import org.omg.CORBA.*;
import java.io.*;
import java.lang.*;
public class encrypt_client
{
    static encrypt encryptimpl;
    public static void main(String args[])
    {
      try
      {

        String result_str,tempstr;
        ORB orb=ORB.init(args,null);
        org.omg.CORBA.Object objref=orb.resolve_initial_references(\"NameService\");

        NamingContextExt ncref=NamingContextExtHelper.narrow(objref);

        String pathname=\"encrypt\";
        encryptimpl=encryptHelper.narrow(ncref.resolve_str(pathname));

        BufferedReader in=new BufferedReader(new InputStreamReader(System.in));

        System.out.println(\"Enter string you want to send to server : \");
        tempstr=in.readLine();
        StringBuffer string1=new StringBuffer(tempstr);
    for(int i=0;i<string1.length();i++)
        {
          string1.setCharAt(i,(char)(string1.charAt(i)+2));
        }
        System.out.println(\"Encrypted string sent to server : \"+string1);

        result_str=encryptimpl.getstr(string1.toString());

        System.out.println(\"Decrypted string recvd from server is as below:\");
        System.out.println(result_str);

      }
      catch(Exception e)
      {
         System.out.println(e);
      }
    }

}


// encrypt_server.java

import encrypt_val.*;
import org.omg.CosNaming.*;
import org.omg.CosNaming.NamingContextPackage.*;
import org.omg.CORBA.*;
import org.omg.PortableServer.*;
import org.omg.PortableServer.POA;
import java.lang.*;
import java.util.*;
import java.text.*;
class serverimpl extends encryptPOA
{
   private ORB orb;
   public void setorb(ORB orb_val)
   {
      orb=orb_val;
   }

   public String getstr(String str1)
   {
     StringBuffer strb1=new StringBuffer(str1);
     Date dateobj=new Date();
     SimpleDateFormat sdf;
     sdf=new SimpleDateFormat(\"hh:mm:ss\");

     String datestr=sdf.format(dateobj).toString();
     datestr=\" \"+datestr+\" \";

     for(int i=0;i<strb1.length();i++)
        {
          strb1.setCharAt(i,(char)(strb1.charAt(i)-2));
          if(strb1.charAt(i)==\' \')
            {
             strb1.insert(i,datestr);
             i=i+datestr.length();
            }
       }
     return(strb1.toString());
   }
}
public class encrypt_server
{
   public static void main(String args[])
   {
     try
     {
         ORB orb=ORB.init(args,null);

         org.omg.CORBA.Object objref1=orb.resolve_initial_references(\"RootPOA\");
         POA rootpoa=POAHelper.narrow(objref1);
         rootpoa.the_POAManager().activate();

         serverimpl serverobj=new serverimpl();
         serverobj.setorb(orb);
         org.omg.CORBA.Object objref2=rootpoa.servant_to_reference(serverobj);
         encrypt href=encryptHelper.narrow(objref2);

         org.omg.CORBA.Object objref3= orb.resolve_initial_references(\"NameService\");
         NamingContextExt ncref=NamingContextExtHelper.narrow(objref3);
         String pathname=\"encrypt\";
         NameComponent path[]=ncref.to_name(pathname);
         ncref.rebind(path,href);


         System.out.println(\"server ready and waiting...\");

         orb.run();

     }
     catch(Exception e)
     {
       System.out.println(e);
     }
   }


}


// Output :

E:\\DIPI1\\corba prgs\\encrypt>java encrypt_client -ORBInitialPort 1050 -ORBInitialHost a

Enter string you want to send to server :
hi how are you
Encrypted string sent to server : jk\"jqy\"ctg\"{qw
Decrypted string recvd from server is as below:
hi 07:15:56  how 07:15:56  are 07:15:56  you

    Related Post:
  1. Corba program of Count Client Applet, IDL,Server, Client

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

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

  4. An applet program to display barchart of given data

  5. Develop a RMI based application for addition of two complex numbers

  6. Application for counting factorial of a given number

  7. Program to show an example of using a Static Nested Class outside the Top-Level Class

  8. Program that will count the number of lines in each file that is specified on the command line

  9. Program to show an example of Polymorphism

  10. An applet program that displays random dot

  11. Program to read the price of an item in decimal form (like 75.95) and print the output in paise (like 7595 paise).

  12. Corba program of reverse string

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

  14. Word list program that reads a text file and makes an alphabetical list of all the words in that file. The list of words is output to another file

  15. Program to copy the elements of an array into another array in reverse order and print them

  16. Program to show the use of Labeled Continue Statement

  17. Program of bubble sort

  18. Program to append a StringBuffer by StringBuffer, String objects and other Basic Data Types

  19. An applet program to draw different shapes

  20. An applet program to perform selection sort