bindi v. parikh id : 07mcg22

Upload: sureshssuthar

Post on 30-May-2018

224 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/14/2019 Bindi v. Parikh Id : 07mcg22

    1/31

    BINDI V. PARIKH

    ID : 07MCG22

    CORBA

    1. The client sends a string to server. Server counts the number of vowel andnumber of consonant present within this string and returns vowel and consonant count

    to client. Implement this application using CORBA.

    PROGRAM

    cnt_Vowel.idl

    module cnt_VowelApp{

    interface cnt_Vowel{

    long vowel(in string str);long cnsnant(in string str);

    };};

    cnt_VowelServant.java

    import cnt_VowelApp.*;import org.omg.CosNaming.*;import org.omg.CosNaming.NamingContextPackage.*;import org.omg.CORBA.*;

    public class cnt_VowelServant extends _cnt_VowelImplBase{

    public int vowel(String str){

    char ch;int cnt=0;

    for(int i=0;i

  • 8/14/2019 Bindi v. Parikh Id : 07mcg22

    2/31

    BINDI V. PARIKH

    ID : 07MCG22

    if(chr=='a' || chr=='e' || chr=='i' || chr=='o' || chr=='u' || chr=='A' || chr=='E' ||chr=='I' || chr=='O' || chr=='U')

    {cntr++;

    }}return (str.length()-cntr);

    }}

    cnt_VowelClient.java

    import cnt_VowelApp.*;import org.omg.CosNaming.*;import org.omg.CosNaming.NamingContextPackage.*;import org.omg.CORBA.*;

    public class cnt_VowelClient{

    public static void main(String args[]){

    try{

    ORB orb = ORB.init(args,null);

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

    NamingContext ncref = NamingContextHelper.narrow(objref);

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

    NameComponent path[] = {nc};

    cnt_Vowel vowelref = cnt_VowelHelper.narrow(ncref.resolve(path));

    int no_vowel = vowelref.vowel(args[0]);int no_consonant = vowelref.cnsnant(args[0]);

    System.out.println("No of vowels are:" + no_vowel);System.out.println("No of consonants are:" + no_consonant);

    }catch(Exception e){

    System.out.println(e);}

    }}

    2

  • 8/14/2019 Bindi v. Parikh Id : 07mcg22

    3/31

    BINDI V. PARIKH

    ID : 07MCG22

    cnt_VowelServer.java

    import cnt_VowelApp.*;import org.omg.CosNaming.*;

    import org.omg.CosNaming.NamingContextPackage.*;import org.omg.CORBA.*;

    public class cnt_VowelServer{

    public static void main(String args[]){

    try{

    ORB orb = ORB.init(args,null);

    cnt_VowelServant vowelref = new cnt_VowelServant();

    orb.connect(vowelref);

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

    NamingContext ncref = NamingContextHelper.narrow(objref);

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

    NameComponent path[] = {nc};

    ncref.rebind(path,vowelref);

    java.lang.Object sync = new java.lang.Object();

    synchronized(sync){

    sync.wait();}

    }catch(Exception e){

    System.out.println(e);}

    }}

    OUTPUT

    C:\JDK16~1.0_1\bin>java cnt_VowelClient BindiParikh -ORBInitialHost localhost -ORBInitialPort 1050No of vowels are:4No of consonants are:7

    C:\JDK16~1.0_1\bin>java cnt_VowelClient SureshSuthar -ORBInitialHost localhost -

    ORBInitialPort 1050No of vowels are:4No of consonants are:8

    3

  • 8/14/2019 Bindi v. Parikh Id : 07mcg22

    4/31

    BINDI V. PARIKH

    ID : 07MCG22

    C:\JDK16~1.0_1\bin>java cnt_VowelClient Rinku -ORBInitialHost localhost -ORBInitialPort 1050No of vowels are:2

    No of consonants are:3

    4

  • 8/14/2019 Bindi v. Parikh Id : 07mcg22

    5/31

    BINDI V. PARIKH

    ID : 07MCG22

    2. The client sends an integer value to server. Server sends the reverse integervalue to client. Implement this application using CORBA. (e.g. value is 678. output will be876). Any integer value can be accepted.

    PROGRAM

    reverse_int.idl

    module reverse_intApp{

    interface reverse_int{

    long int_rev(in long num);};

    };

    reverse_intServant.java

    import reverse_intApp.*;import org.omg.CosNaming.*;import org.omg.CosNaming.NamingContextPackage.*;import org.omg.CORBA.*;

    public class reverse_intServant extends _reverse_intImplBase{

    public int int_rev(int num){

    int temp = num;

    int rev=0;int rem=0;

    while(temp != 0){

    rem = temp % 10;temp = temp /10;rev = rev * 10 + rem;

    }return rev;

    }}

    reverse_intClient.java

    import reverse_intApp.*;import org.omg.CosNaming.*;import org.omg.CosNaming.NamingContextPackage.*;import org.omg.CORBA.*;import java.io.*;

    public class reverse_intClient{

    public static void main(String args[]){try

    5

  • 8/14/2019 Bindi v. Parikh Id : 07mcg22

    6/31

    BINDI V. PARIKH

    ID : 07MCG22

    {ORB orb = ORB.init(args,null);

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

    NamingContext ncref = NamingContextHelper.narrow(objref);

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

    NameComponent path[] = {nc};

    reverse_int revref = reverse_intHelper.narrow(ncref.resolve(path));

    System.out.println("Enter the number:");

    InputStreamReader ir = new InputStreamReader(System.in);

    BufferedReader br = new BufferedReader(ir);

    int num = Integer.parseInt(br.readLine());

    int reverse_no = revref.int_rev(num);

    System.out.println("The reversed number is:" + reverse_no);}catch(Exception e){

    System.out.println(e);

    }}

    }

    reverse_intServer.java

    import reverse_intApp.*;import org.omg.CosNaming.*;import org.omg.CosNaming.NamingContextPackage.*;import org.omg.CORBA.*;

    public class reverse_intServer{

    public static void main(String args[]){

    try{

    ORB orb = ORB.init(args,null);

    reverse_intServant revref = new reverse_intServant();

    orb.connect(revref);

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

    NamingContext ncref = NamingContextHelper.narrow(objref);

    6

  • 8/14/2019 Bindi v. Parikh Id : 07mcg22

    7/31

    BINDI V. PARIKH

    ID : 07MCG22

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

    NameComponent path[] = {nc};

    ncref.rebind(path,revref);

    java.lang.Object sync = new java.lang.Object();

    synchronized(sync){

    sync.wait();}

    }catch(Exception e){

    System.out.println(e);}

    }}

    OUTPUT

    C:\JDK16~1.0_1\bin>java reverse_intClient -ORBInitialHost localhost -ORBInitialPort 1050Enter the number:45612The reversed number is:21654

    7

  • 8/14/2019 Bindi v. Parikh Id : 07mcg22

    8/31

    BINDI V. PARIKH

    ID : 07MCG22

    3. Clients sends a number to server. Server adds the digits of the number and sendsthe result to client. Implement using CORBA.

    PROGRAM

    sum_digit.idl

    module sum_digitApp{

    interface sum_digit{

    long sum(in long num);};

    };

    sum_digitServant.java

    import sum_digitApp.*;import org.omg.CosNaming.*;import org.omg.CosNaming.NamingContextPackage.*;import org.omg.CORBA.*;

    public class sum_digitServant extends _sum_digitImplBase{

    public int sum(int num){

    int temp = num;int sum=0;

    int rem=0;

    while(temp != 0){

    rem = temp % 10;temp = temp /10;sum = sum + rem;

    }return sum;

    }}

    sum_digitClient.java

    import sum_digitApp.*;import org.omg.CosNaming.*;import org.omg.CosNaming.NamingContextPackage.*;import org.omg.CORBA.*;import java.io.*;

    public class sum_digitClient{

    public static void main(String args[])

    { try{

    8

  • 8/14/2019 Bindi v. Parikh Id : 07mcg22

    9/31

    BINDI V. PARIKH

    ID : 07MCG22

    ORB orb = ORB.init(args,null);

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

    NamingContext ncref = NamingContextHelper.narrow(objref);

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

    NameComponent path[] = {nc};

    sum_digit sumref = sum_digitHelper.narrow(ncref.resolve(path));

    System.out.print("Enter the number:");

    InputStreamReader ir = new InputStreamReader(System.in);

    BufferedReader br = new BufferedReader(ir);

    int num = Integer.parseInt(br.readLine());

    int sum_dgt = sumref.sum(num);

    System.out.print("The number is:" + num);System.out.println();System.out.print("Sum of digits:" + sum_dgt);

    }catch(Exception e){

    System.out.println(e);}

    }}

    sum_digitServer.java

    import sum_digitApp.*;import org.omg.CosNaming.*;import org.omg.CosNaming.NamingContextPackage.*;import org.omg.CORBA.*;

    public class sum_digitServer{

    public static void main(String args[]){

    try{

    ORB orb = ORB.init(args,null);

    sum_digitServant sumref = new sum_digitServant();

    orb.connect(sumref);

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

    9

  • 8/14/2019 Bindi v. Parikh Id : 07mcg22

    10/31

    BINDI V. PARIKH

    ID : 07MCG22

    NamingContext ncref = NamingContextHelper.narrow(objref);

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

    NameComponent path[] = {nc};

    ncref.rebind(path,sumref);

    java.lang.Object sync = new java.lang.Object();

    synchronized(sync){

    sync.wait();}

    }

    catch(Exception e){

    System.out.println(e);}

    }}

    OUTPUT

    C:\JDK16~1.0_1\bin>java sum_digitClient -ORBInitialHost localhost -ORBInitialPort 1050Enter the number:4567

    The number is:4567Sum of digits:22

    C:\JDK16~1.0_1\bin>java sum_digitClient -ORBInitialHost localhost -ORBInitialPort 1050Enter the number:894512The number is:894512Sum of digits:29

    10

  • 8/14/2019 Bindi v. Parikh Id : 07mcg22

    11/31

    BINDI V. PARIKH

    ID : 07MCG22

    4. Clients sends a number to server. Server deletes all 0sfrom the number and thengenerates new number. Server sends a new number to client. Implement using CORBA.(e.g: Input number is 1024. output should be 124. Input is 2040, output is 24). Any numbercan be sent by client to server.

    remove_zero.idl

    module remove_zeroApp{

    interface remove_zero{

    long rem_zero(in long num);};

    };

    remove_zeroServant.java

    import remove_zeroApp.*;import org.omg.CosNaming.*;import org.omg.CosNaming.NamingContextPackage.*;import org.omg.CORBA.*;

    public class remove_zeroServant extends _remove_zeroImplBase{

    public int rem_zero(int num){

    String s = num + "";

    String str = s.replaceAll("0","");int res = Integer.parseInt(str);

    return res;}

    }

    remove_zeroClient.java

    import remove_zeroApp.*;import org.omg.CosNaming.*;import org.omg.CosNaming.NamingContextPackage.*;import org.omg.CORBA.*;import java.io.*;

    public class remove_zeroClient{

    public static void main(String args[]){

    try{

    ORB orb = ORB.init(args,null);

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

    NamingContext ncref = NamingContextHelper.narrow(objref);

    11

  • 8/14/2019 Bindi v. Parikh Id : 07mcg22

    12/31

    BINDI V. PARIKH

    ID : 07MCG22

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

    NameComponent path[] = {nc};

    remove_zero remref = remove_zeroHelper.narrow(ncref.resolve(path));

    System.out.println("Enter the number:");

    InputStreamReader ir = new InputStreamReader(System.in);

    BufferedReader br = new BufferedReader(ir);

    int num = Integer.parseInt(br.readLine());

    int res_no = remref.rem_zero(num);

    System.out.println("The number after zeros are removed is:" + res_no);}catch(Exception e){

    System.out.println(e);}

    }}

    remove_zeroServer.java

    import remove_zeroApp.*;import org.omg.CosNaming.*;import org.omg.CosNaming.NamingContextPackage.*;import org.omg.CORBA.*;

    public class remove_zeroServer{

    public static void main(String args[]){

    try{

    ORB orb = ORB.init(args,null);

    remove_zeroServant remref = new remove_zeroServant();

    orb.connect(remref);

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

    NamingContext ncref = NamingContextHelper.narrow(objref);

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

    NameComponent path[] = {nc};

    ncref.rebind(path,remref);

    12

  • 8/14/2019 Bindi v. Parikh Id : 07mcg22

    13/31

    BINDI V. PARIKH

    ID : 07MCG22

    java.lang.Object sync = new java.lang.Object();

    synchronized(sync)

    { sync.wait();}

    }catch(Exception e){

    System.out.println(e);}

    }}

    OUTPUT

    C:\JDK16~1.0_1\bin>java remove_zeroClient -ORBInitialHost localhost -ORBInitialPort 1050Enter the number:10405The number after zeros are removed is:145

    C:\JDK16~1.0_1\bin>java remove_zeroClient -ORBInitialHost localhost -ORBInitialPort 1050Enter the number:1024The number after zeros are removed is:124

    13

  • 8/14/2019 Bindi v. Parikh Id : 07mcg22

    14/31

    BINDI V. PARIKH

    ID : 07MCG22

    5. The Client sends a number to server. Server checks that how many even digits arepresent within the number. Even digits count will be sent to client. Implement usingCORBA.

    PROGRAM

    find_evendigit.idl

    module find_evendigitApp{

    interface find_evendigit{

    long cnt_evendigit(in long num);};

    };

    find_evendigitServant.java

    import find_evendigitApp.*;import org.omg.CosNaming.*;import org.omg.CosNaming.NamingContextPackage.*;import org.omg.CORBA.*;

    public class find_evendigitServant extends _find_evendigitImplBase{

    public int cnt_evendigit(int num){

    int temp = num;

    int cnt=0;int rem;

    while(temp != 0){

    rem = temp % 10;temp = temp /10;if((rem % 2) == 0)

    cnt ++;}return cnt;

    }}

    find_evendigitClient.java

    import find_evendigitApp.*;import org.omg.CosNaming.*;import org.omg.CosNaming.NamingContextPackage.*;import org.omg.CORBA.*;import java.io.*;

    public class find_evendigitClient

    { public static void main(String args[]){

    14

  • 8/14/2019 Bindi v. Parikh Id : 07mcg22

    15/31

    BINDI V. PARIKH

    ID : 07MCG22

    try{

    ORB orb = ORB.init(args,null);

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

    NamingContext ncref = NamingContextHelper.narrow(objref);

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

    NameComponent path[] = {nc};

    find_evendigit evenref = find_evendigitHelper.narrow(ncref.resolve(path));

    System.out.println("Enter the number:");

    InputStreamReader ir = new InputStreamReader(System.in);

    BufferedReader br = new BufferedReader(ir);

    int num = Integer.parseInt(br.readLine());

    int res_no = evenref.cnt_evendigit(num);

    System.out.println("There are " +res_no+ " Even digits in the " + num +".");}catch(Exception e){

    System.out.println(e);}

    }}

    find_evendigitServer.java

    import find_evendigitApp.*;import org.omg.CosNaming.*;import org.omg.CosNaming.NamingContextPackage.*;import org.omg.CORBA.*;

    public class find_evendigitServer{

    public static void main(String args[]){

    try{

    ORB orb = ORB.init(args,null);

    find_evendigitServant evenref = new find_evendigitServant();

    orb.connect(evenref);

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

    15

  • 8/14/2019 Bindi v. Parikh Id : 07mcg22

    16/31

    BINDI V. PARIKH

    ID : 07MCG22

    NamingContext ncref = NamingContextHelper.narrow(objref);

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

    NameComponent path[] = {nc};

    ncref.rebind(path,evenref);

    java.lang.Object sync = new java.lang.Object();

    synchronized(sync){

    sync.wait();}

    }catch(Exception e)

    {System.out.println(e);

    }}

    }

    OUTPUT

    C:\jdk1.6.0_11\bin>java find_evendigitClient -ORBInitialHost localhost -ORBInitialPort 1050Enter the number:346781

    There are 3 Even digits in the 346781.

    C:\jdk1.6.0_11\bin>java find_evendigitClient -ORBInitialHost localhost -ORBInitialPort 1050Enter the number:44278There are 4 Even digits in the 44278.

    16

  • 8/14/2019 Bindi v. Parikh Id : 07mcg22

    17/31

    BINDI V. PARIKH

    ID : 07MCG22

    6. Client sends string to the server. Server deletes all repeated character from thestring. New string will be sent to the client. Implement using CORBA.(e.g. the inputstring is access, output string will be aces). Any string can be accepted.

    PROGRAM

    replaceChar.idl

    module replaceCharApp{

    interface replaceChar{

    string replaceC(in string str);};

    };

    replaceCharServant.java

    import replaceCharApp.*;import org.omg.CosNaming.*;import org.omg.CosNaming.NamingContextPackage.*;import org.omg.CORBA.*;

    class replaceCharServant extends _replaceCharImplBase{

    public String replaceC(String str){

    String temp="";

    int flag=0;temp=str.charAt(0) + "";

    for(int i=1;i

  • 8/14/2019 Bindi v. Parikh Id : 07mcg22

    18/31

    BINDI V. PARIKH

    ID : 07MCG22

    {

    ORB orb = ORB.init(args,null);

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

    NamingContext ncRef = NamingContextHelper.narrow(objRef);

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

    NameComponent path[] = {nc};

    replaceChar rcRef = replaceCharHelper.narrow(ncRef.resolve(path));

    System.out.println(rcRef.replaceC(args[0]);}

    }

    replaceCharServer.java

    import replaceCharApp.*;import org.omg.CosNaming.*;import org.omg.CosNaming.NamingContextPackage.*;import org.omg.CORBA.*;

    class replaceCharServer{

    public static void main(String args[]) throws Exception

    {ORB orb = ORB.init(args,null);

    replaceCharServant rcRef = new replaceCharServant();

    orb.connect(rcRef);

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

    NamingContext ncRef = NamingContextHelper.narrow(objRef);

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

    NameComponent path[] = {nc};

    ncRef.rebind(path,rcRef);

    java.lang.Object sync = new java.lang.Object();

    synchronized(sync){

    sync.wait();}

    }}

    18

  • 8/14/2019 Bindi v. Parikh Id : 07mcg22

    19/31

    BINDI V. PARIKH

    ID : 07MCG22

    OUTPUT

    C:\jdk1.6.0_11\bin>java replaceCharClient BindiParikh -ORBInitialHost localhost-ORBInitialPort 1050

    BindParkh

    C:\jdk1.6.0_11\bin>java replaceCharClient ShraddhaPatel -ORBInitialHost localhost -ORBInitialPort 1050ShradPtel

    19

  • 8/14/2019 Bindi v. Parikh Id : 07mcg22

    20/31

    BINDI V. PARIKH

    ID : 07MCG22

    7. Client sends base and power (x,y) to the server. Server generates x ^y and sendsto client. Implement using CORBA.

    PROGRAM

    PowerApp.idl

    module PowerApp{

    interface IntPower{

    double Bpower(in long x,in long y);};

    };

    BPwrServant.java

    import PowerApp.*;import org.omg.CosNaming.*;import org.omg.CosNaming.NamingContextPackage.*;import org.omg.CORBA.*;

    public class BPwrServant extends _IntPowerImplBase{

    public double Bpower(int x,int y){

    return(Math.pow(x,y));}

    }

    BPwrClient.java

    import PowerApp.*;import org.omg.CosNaming.*;import org.omg.CosNaming.NamingContextPackage.*;import org.omg.CORBA.*;

    public class BPwrClient{

    public static void main(String args[]){

    try{

    ORB orb = ORB.init(args,null);

    BPwrServant BPref = new BPwrServant();

    orb.connect(BPref);

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

    NamingContext ncRef = NamingContextHelper.narrow(objref);NameComponent nc = new NameComponent("IntPower", " ");

    20

  • 8/14/2019 Bindi v. Parikh Id : 07mcg22

    21/31

    BINDI V. PARIKH

    ID : 07MCG22

    NameComponent path[] = {nc};

    IntPower BPRef = IntPowerHelper.narrow(ncRef.resolve(path));

    int x,y;x=Integer.parseInt(args[0]);y=Integer.parseInt(args[1]);

    double bp = BPRef.Bpower(x,y);

    System.out.println(x + " ^ " + y + " = " + bp);}catch(Exception e){

    System.err.println(e);

    e.printStackTrace(System.out);}

    }}

    BPwrServer.java

    import PowerApp.*;import org.omg.CosNaming.*;import org.omg.CosNaming.NamingContextPackage.*;import org.omg.CORBA.*;

    public class BPwrServer{

    public static void main(String a[]){

    try{

    ORB orb = ORB.init(a,null);

    BPwrServant BPwrref = new BPwrServant();

    orb.connect(BPwrref);

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

    NamingContext ncRef = NamingContextHelper.narrow(objref);

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

    NameComponent path[] = {nc};

    ncRef.rebind(path,BPwrref);

    java.lang.Object sync = new java.lang.Object();

    synchronized(sync){

    21

  • 8/14/2019 Bindi v. Parikh Id : 07mcg22

    22/31

    BINDI V. PARIKH

    ID : 07MCG22

    sync.wait();}

    }catch(Exception e)

    { System.err.println(e);e.printStackTrace(System.out);

    }}

    }

    OUTPUT

    C:\jdk1.6.0_11\bin>java BPwrClient 2 4 -ORBInitialHost localhost -ORBInitialPort 10502 ^ 4 = 16.0

    C:\jdk1.6.0_11\bin>java BPwrClient 3 4 -ORBInitialHost localhost -ORBInitialPort 10503 ^ 4 = 81.0

    22

  • 8/14/2019 Bindi v. Parikh Id : 07mcg22

    23/31

    BINDI V. PARIKH

    ID : 07MCG22

    8. The client module sends a string to server. Server checks whether the string ispalindrome or not and return appropriate message to client String is palindrome/String is not palindrome. Implement this application using CORBA.

    PROGRAM

    PalinApp.idl

    module PalinApp{

    interface Palin{

    string strPalin(in string str);};

    };

    PalinServant.javaimport PalinApp.*;import org.omg.CosNaming.*;import org.omg.CosNaming.NamingContextPackage.*;import org.omg.CORBA.*;

    class PalinServant extends _PalinImplBase{

    public String strPalin(String str){

    String org="",str1=str;

    StringBuffer sbr = new StringBuffer(str);

    org=sbr.reverse().toString();

    if(org.equals(str1))return "Palindrome";

    elsereturn "Not Palindrome";

    }}

    PalinClient.java

    import PalinApp.*;import org.omg.CosNaming.*;import org.omg.CosNaming.NamingContextPackage.*;import org.omg.CORBA.*;

    public class PalinClient{

    public static void main(String args[]){

    try{ORB orb = ORB.init(args,null);

    23

  • 8/14/2019 Bindi v. Parikh Id : 07mcg22

    24/31

    BINDI V. PARIKH

    ID : 07MCG22

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

    NamingContext ncRef = NamingContextHelper.narrow(objRef);

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

    NameComponent path[] = {nc};

    Palin palinRef = PalinHelper.narrow(ncRef.resolve(path));

    String palin = palinRef.strPalin("abcd");

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

    {}}

    }

    PalinServer.javaimport PalinApp.*;import org.omg.CosNaming.*;import org.omg.CosNaming.NamingContextPackage.*;import org.omg.CORBA.*;

    public class PalinServer

    {public static void main(String args[]){

    try{

    ORB orb = ORB.init(args,null);

    PalinServant palinRef = new PalinServant();

    orb.connect(palinRef);

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

    NamingContext ncRef = NamingContextHelper.narrow(objRef);

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

    NameComponent path[] = {nc};

    ncRef.rebind(path,palinRef);

    java.lang.Object sync = new java.lang.Object();

    synchronized(sync){sync.wait();

    24

  • 8/14/2019 Bindi v. Parikh Id : 07mcg22

    25/31

    BINDI V. PARIKH

    ID : 07MCG22

    }}catch(Exception e){}

    }}OUTPUT

    C:\jdk1.6.0_11\bin>java PalinClient madam -ORBInitialHost localhost -ORBInitialPort 1050Palindrome

    C:\jdk1.6.0_11\bin>java PalinClient hello -ORBInitialHost localhost -ORBInitialPort 1050Not Palindrome

    25

  • 8/14/2019 Bindi v. Parikh Id : 07mcg22

    26/31

    BINDI V. PARIKH

    ID : 07MCG22

    9. Client sends an integer value to server. Server checks the number is prime or notand sends the message to client. Implement this application using CORBA.

    PROGRAM

    find_prime.idl

    module find_primeApp{

    interface find_prime{

    long findprime(in long num);};

    };

    find_primeServant.java

    import find_primeApp.*;import org.omg.CosNaming.*;import org.omg.CosNaming.NamingContextPackage.*;import org.omg.CORBA.*;

    public class find_primeServant extends _find_primeImplBase{

    public int findprime(int num){

    int temp = num;int result = 0;

    for(int i=2;i

  • 8/14/2019 Bindi v. Parikh Id : 07mcg22

    27/31

    BINDI V. PARIKH

    ID : 07MCG22

    NamingContext ncref = NamingContextHelper.narrow(objref);

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

    NameComponent path[] = {nc};

    find_prime primeref = find_primeHelper.narrow(ncref.resolve(path));

    System.out.print("Enter the number:");

    InputStreamReader ir = new InputStreamReader(System.in);

    BufferedReader br = new BufferedReader(ir);

    int num = Integer.parseInt(br.readLine());

    int result = primeref.findprime(num);

    if(result == 1)System.out.print("The number "+num+" is not prime");

    elseSystem.out.println("The number "+num+" is prime");

    }catch(Exception e){

    System.out.println(e);}

    }}

    find_primeServer.java

    import find_primeApp.*;import org.omg.CosNaming.*;import org.omg.CosNaming.NamingContextPackage.*;import org.omg.CORBA.*;

    public class find_primeServer{

    public static void main(String args[]){

    try{

    ORB orb = ORB.init(args,null);

    find_primeServant primeref = new find_primeServant();

    orb.connect(primeref);

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

    NamingContext ncref = NamingContextHelper.narrow(objref);

    27

  • 8/14/2019 Bindi v. Parikh Id : 07mcg22

    28/31

    BINDI V. PARIKH

    ID : 07MCG22

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

    NameComponent path[] = {nc};

    ncref.rebind(path,primeref);

    java.lang.Object sync = new java.lang.Object();

    synchronized(sync){

    sync.wait();}

    }catch(Exception e){

    System.out.println(e);

    }}

    }

    OUTPUT

    C:\jdk1.6.0_11\bin>java find_primeClient -ORBInitialHost localhost -ORBInitialPort 1050Enter the number:10The number 10 is not prime

    C:\jdk1.6.0_11\bin>java find_primeClient -ORBInitialHost localhost -ORBInitialPort 1050Enter the number:97

    The number 97 is prime

    28

  • 8/14/2019 Bindi v. Parikh Id : 07mcg22

    29/31

    BINDI V. PARIKH

    ID : 07MCG22

    10. Client sends a string to server. Server encodes the string and sends it toclient.Each character of the string is replaced by the next character of alphabet list.(public string is encoded as qvcmjd). Last alphabet (z) can not be replaced.(e.g:zebra is encoded as zfcsb).Implement using CORBA.

    PROGRAM

    str_encode.idl

    module str_encodeApp{

    interface str_encode{

    string encode(in string str);};

    };

    str_encodeServant.java

    import str_encodeApp.*;import org.omg.CosNaming.*;import org.omg.CosNaming.NamingContextPackage.*;import org.omg.CORBA.*;

    public class str_encodeServant extends _str_encodeImplBase{

    public String encode(String str){

    String temp="";

    for(int i=0;i

  • 8/14/2019 Bindi v. Parikh Id : 07mcg22

    30/31

    BINDI V. PARIKH

    ID : 07MCG22

    public class str_encodeClient{

    public static void main(String args[]){

    try{ORB orb = ORB.init(args,null);

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

    NamingContext ncref = NamingContextHelper.narrow(objref);

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

    NameComponent path[] = {nc};

    str_encode encoderef = str_encodeHelper.narrow(ncref.resolve(path));

    String str = encoderef.encode(args[0]);

    System.out.println("The encoded string is:" + str);

    }catch(Exception e){

    System.out.println(e);}

    }

    }

    str_encodeServer.java

    import str_encodeApp.*;import org.omg.CosNaming.*;import org.omg.CosNaming.NamingContextPackage.*;import org.omg.CORBA.*;

    public class str_encodeServer{

    public static void main(String args[]){

    try{

    ORB orb = ORB.init(args,null);

    str_encodeServant encoderef = new str_encodeServant();

    orb.connect(encoderef);

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

    NamingContext ncref = NamingContextHelper.narrow(objref);

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

    30

  • 8/14/2019 Bindi v. Parikh Id : 07mcg22

    31/31

    BINDI V. PARIKH

    ID : 07MCG22

    NameComponent path[] = {nc};

    ncref.rebind(path,encoderef);

    java.lang.Object sync = new java.lang.Object();

    synchronized(sync){

    sync.wait();}

    }catch(Exception e){

    System.out.println(e);

    }}

    }

    OUTPUT

    C:\jdk1.6.0_11\bin>java str_encodeClient NishaBhatt -ORBInitialHost localhost -ORBInitialPort1050The encoded string is:OjtibCibuu

    C:\jdk1.6.0_11\bin>java str_encodeClient Zebra -ORBInitialHost localhost -ORBInitialPort 1050The encoded string is:Zfcsb