Tuesday, 9 June 2015

Program in CORBA which takes a long sentence from client (at least 7 words), passes to the server, server separates out each word and sends back


Code for Program in CORBA which takes a long sentence from client (at least 7 words), passes to the server, server separates out each word and sends back in Java



 



 
import revsent_val.*;
import org.omg.CosNaming.*;
import org.omg.CosNaming.NamingContextPackage.*;
import org.omg.CORBA.*;
import java.io.*;
import java.lang.*;
publicclass revsent_client
{
    static revsent revsentimpl;
    publicstaticvoid 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="revsent";
        revsentimpl=revsentHelper.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);

        System.out.println("String sent to server : "+string1);

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

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

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

}


// revsent_server.java

import revsent_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.*;

class serverimpl extends revsentPOA
{
   private ORB orb;
   publicvoid setorb(ORB orb_val)
   {
      orb=orb_val;
   }

   public String getstr(String str1)
   {
     StringBuffer strb1=new StringBuffer(str1);
     strb1.insert(0,' ');
     String ans_str="";
     int len=strb1.length()-1;
     int j=0;
     System.out.println("length:"+len);

     for(int i=len;i>=0;i--)
     {
       if(strb1.charAt(i)==' ')
         {
          ans_str+=strb1.substring(i+1,len+1);
          j=i-1;
          break;
        }
     }

     for(int i=j;i>=0;i--)
     {
       if(strb1.charAt(i)==' ' || i==0)
         {
          ans_str+=strb1.substring(i,j+1);
          j=i-1;
          }
     }

     return(ans_str);
   }
}
publicclass revsent_server
{
   publicstaticvoid 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);
         revsent href=revsentHelper.narrow(objref2);

         org.omg.CORBA.Object objref3= orb.resolve_initial_references("NameService");
         NamingContextExt ncref=NamingContextExtHelper.narrow(objref3);
         String pathname="revsent";
         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\revsent>java revsent_client -ORBInitialPort 1050 -ORBInitialHost a

Enter string you want to send to server :
hi thisis the test of reversing a string by its words

String sent to server : hi thisis the test of reversing a string by its words

String recvd from server isas below:
words its by string a reversing of test the isthis hi

No comments:

Post a Comment