Вы находитесь на странице: 1из 33

RAJALAKSHMI ENGINEERING COLLEGE Department of Computer Application

Subject Co e !MC"#$% Staff Name ! Mr( A( Ant)oni*an Subject Name! MIDDLE&ARE LA'

1. Create a distributed application to download various files from various servers using RMI 2. Create a Java Bean to draw various graphical shapes and display it using or without using B ! ". %. ,. 1. 2. 4. evelop an #nterprise Java Bean for Ban$ing operations evelop an #nterprise Java Bean for &ibrary operations evelop a component for converting the currency values using C-M . ./#0 evelop a component for encryption and decryption using C-M . ./#0 evelop a component for retrieving information from message bo3 using C-M . ./#0 evelop a middleware component for retrieving 5toc$ Mar$et #3change information using C-RB( 16. evelop a middleware component for retrieving 7eather +orecast information using C-RB(

'. Create an (ctive)* control for +ile operations

E+(No! %

An Application ,*in- RMI

Aim! 0o create a distributed application to download various files from various servers using RMI Al-orit)m! 1. Create four files 8 file interface9 file implementation9 file client and fileserver 2. In the file interface9 class specify the prototype of the method that is to be implemented in the file implementation class ". In the file implementation class9 specify the implementation coding for the method defined earlier :download file;<= %. 0ry to read the contents of a file in this class '. In the fileclient class try to write some contents into a file ,. In the fileserver class9 try to register . bind the methods with the rmiregistry 1. Compile all the files and e3ecute as specified to get the desired output. .ro-ram /ileInterface(ja0a import >ava.rmi.Remote? import >ava.rmi.Remote#3ception? public interface +ileInterface e3tends Remote @ public byte;< download+ile:5tring file/ame= throws Remote#3ception? A /ileImpl(ja0a import >ava.io.B? import >ava.rmi.B? import >ava.rmi.server.CnicastRemote-b>ect? public class +ileImpl e3tends CnicastRemote-b>ect implements +ileInterface @ private 5tring name? public +ileImpl:5tring s= throws Remote#3ception@ 2

super:=? name D s? A public byte;< download+ile:5tring file/ame=@ try @ +ile file D new +ile:file/ame=? byte buffer;< D new byte;:int=file.length:=<? BufferedInput5tream input D new BufferedInput5tream:new +ileInput5tream:file/ame==? input.read:buffer969buffer.length=? input.close:=? return:buffer=? A catch:#3ception e=@ 5ystem.out.println:E+ileImplF EGe.getMessage:==? e.print5tac$0race:=? return:null=? A A A /ileSer0er(ja0a import >ava.io.B? import >ava.rmi.B? public class +ile5erver @ public static void main:5tring argv;<= @ try @ +ileInterface fi D new +ileImpl:E+ile5erverE=? /aming.rebind:E..121.6.6.1.+ile5erverE9 fi=? A catch:#3ception e= @ 5ystem.out.println:E+ile5erverF EGe.getMessage:==? e.print5tac$0race:=? A A A /ileClient(ja0a import >ava.io.B? import >ava.rmi.B? public class +ileClient@ public static void main:5tring argv;<= @ if:argv.length HD 2= @ 5ystem.out.println:ECsageF >ava +ileClient file/ame machine/ameE=? 5ystem.e3it:6=?

"

A try @ 5tring name D E..E G argv;1< G E.+ile5erverE? +ileInterface fi D :+ileInterface= /aming.loo$up:name=? byte;< filedata D fi.download+ile:argv;6<=? 5ystem.out.println:Ienter the file to downloadJ=? BufferedReader br D new BufferedReader:new Input5treamReader:system.in==? 5tring newname D br.read&ine:=? +ile file D new +ile:newname=? Buffered-utput5tream output D new Buffered-utput5tream:new +ile-utput5tream:file.get/ame:===? output.write:filedata969filedata.length=? output.flush:=? output.close:=? A catch:#3ception e= @ 5ystem.err.println:E+ile5erver e3ceptionF EG e.getMessage:==? e.print5tac$0race:=? A A A E+ecution Ser0er fol er 1interface(ja0a2fileimpl(ja0a2file *er0er(ja0a3 1. Compile all the >ava program using :>avac filename.>ava= 2. enter the :start rmiregistry= in command line ". create stub and s$eleton using :rmic +ileImpl= %.create one file i.e a.t3t in server folder '. Run the server using :>ava +ile5erver= Client folder;file interface.>ava9fileclient.>ava9copy the stub and s$eleton from server folder and paste it in client folder< 1. Compile all the >ava program using :>avac filename.>ava= :0he ne3t contains two parameters +irst is the te3t file created by the user second is machine IK (ddress= 2. Run the Client using :>ava +ileClient a.t3t 142.1,2.6.1'%= 1. ne3t step you will give the file name to download the file :#nter the file name to download F b.t3t= 2. a.t3t and b.t3t contains the same content.

E+(No! #

Application u*in- Applet*

Aim! to create a Java Bean to draw various graphical shapes and display it using or without using B ! Al-orit)m! 1. Create a class (ppletdemo which e3tends (pplet superclass and which implements (ction&istener interface 2. Create five buttons with the reLuired captions and add them to the container ". Register the buttons with the (ction&istener interface %. In the (ctionperformed := method9 with the help of the instance9 perform the action respectively '. In the paint:= method9 chec$ which button is pressed and display the shapes accordingly .ro-ram import >ava.awt.B? import >ava.applet.B? import >ava.awt.event.B? ..Mapplet codeDE(ppletdemoE heightD'66 widthD'66NM.appletN public class (ppletdemo e3tends (pplet implements (ction&istener @ 5tring s? Button b19b2? public void init:= @ b1D new Button:E0estE=? b2Dnew Button:EcircleE=? add:b1=? add:b2=? b1.add(ction&istener:this=? b2.add(ction&istener:this=? A public void actionKerformed:(ction#vent ae= @ sDae.get(ctionCommand:=? '

repaint:=? A public void paint:Oraphics g= @ try @ if:s.eLuals:E0estE==? g.draw-val:1229'"9,291'=? ..g.setColor:2129 2"9%'=? if:s.eLuals:EcircleE==? g.drawRect:122912291229122=? A catch:/ullKointer#3ception e= @A A A Sample Output

E+(No ! 4

De0elopin- an Enterpri*e Ja0a 'ean for Librar5 operation*

Aim ! 0o develop an #nterprise Java Bean for &ibrary operations Al-ort)m ! 1. Create five programs 8 Boo$9 Boo$bome9 Boo$bean9 Boo$e3ception9 and Boo$client 2. In the Boo$home class >ust invo$e the create:= method with appropriate arguments ". In the Boo$ class9 >ust define the prototytpes of addboo$:=9 removeboo$:= and getcontents:= methods %. In the Boo$bean class provide the implementation for the various methods '. In the Boo$e3ception class provide the implementation for Boo$#3ception ,. In the Boo$client class get the customer name and the various boo$s he wants9 also perform the other operations accordingly .ro-ram Boo$) Remote interface import >ava3.e>b.B? import >ava.rmi.B? import >ava.util.B? public interface Boo$ e3tends #JB-b>ect @ public void addBoo$:5tring title= throws Remote#3ception? public void removeBoo$:5tring title= throws Remote#3ception9Boo$#3ception? public Pector getContents:= throws Remote#3ception? A Boo$)Qome interface import >ava.io.5erialiRable? import >ava.rmi.Remote#3ception? import >ava3.e>b.Create#3ception? import >ava3.e>b.#JBQome? public interface Boo$Qome e3tends #JBQome @ public Boo$ create:5tring person= throws Remote#3ception9Create#3ception? public Boo$ create:5tring person95tring id= throws Remote#3ception9Create#3ception? A

Boo$ Bean class import >ava.util.B? import >ava3.e>b.B? public class Boo$#JB implements 5essionBean @ 5tring Customer/ame? 5tring customerId? Pector contents? public void e>bCreate:5tring person= throws Create#3ception @ if:personDDnull= throw new Create#3ception:ESn/ull person not allowedE=? else Customer/ameD person? 5ystem.out.println:ESnCustomer nameF EGperson=? customerId D E6E? contents D new Pector:=? A public void e>bCreate:5tring person95tring id= throws Create#3ception @ if:personDDnull= throw new Create#3ception:ESn/ull person not allowedE=? else Customer/ameD person? 5ystem.out.println:ESnCustomer nameF EGperson=? 2

customerId D E6E? contents D new Pector:=? A public void addBoo$:5tring title= @ contents.add#lement:title=? A public void removeBoo$:5tring title= throws Boo$#3ception @ boolean result D contents.remove#lement:title=? if:resultDDfalse= throw new Boo$#3ception:titleGE Boo$ is not in cartE=? A public Pector getContents:= @ return contents? A public Boo$#JB:= @A public void e>b(ctivate:= @A public void e>bKassivate:= @A public void e>bRemove:= @A public void set5essionConte3t:5essionConte3t ct3= @A A

Boo$)#3ception 4

public class Boo$#3ception e3tends #3ception @ public Boo$#3ception:= @A public Boo$#3ception:5tring msg= @ super:msg=? A A

'oo67Client
import >ava3.naming.B? import >ava3.rmi.B? import >ava.rmi.B? import >ava.io.B? import >ava.util.B? public class Boo$Client @ public static void main:5tring arg;<= @ #numeration enum? Pector boo$&ist? Boo$ shoppingCart?

16

try @ Kroperties p D new Kroperties:=? p.put:Conte3t.I/I0I(&TC-/0#*0T+(C0-RU9Eweblogic.>ndi.7&InitialConte3t+actor yE=? p.put:Conte3t.KR-PI #RTCR&9Et"F..localhostF1661E=? p.put:Conte3t.5#CCRI0UTKRI/CIK(&9EmcaE=? p.put:Conte3t.5#CCRI0UTCR# #/0I(&59EmcastudentE=? InitialConte3t ict D new InitialConte3t:p=? 5ystem.out.println:EConte3t sucessfulE=? -b>ect t D ict.loo$up:EBoo$#JB2E=? 5ystem.out.println:E&oo$up successfulE=? Boo$Qome home D :Boo$Qome=KortableRemote-b>ect.narrow:t9Boo$Qome.class=? shoppingCart D home.create:E5ivaE9E12"E=? BufferedReader br D new BufferedReader:new Input5treamReader:5ystem.in==? 5ystem.out.println:ESn#nter customer name E=? 5tring cust D br.read&ine:=? 5ystem.out.println:ESn#nter the boo$name C wantF E=? 5tring boo$1 D br.read&ine:=? shoppingCart.addBoo$:boo$1=? 5ystem.out.println:ESn#nter the boo$name C wantF E=? 5tring boo$2 D br.read&ine:=? shoppingCart.addBoo$:boo$2=? 5ystem.out.println:ESn#nter the boo$name C wantF E=? 5tring boo$" D br.read&ine:=?

11

shoppingCart.addBoo$:boo$"=? 5ystem.out.println:ESnCustomer name is FEGcust=? 5ystem.out.println:E5elected boo$s are listed belowE=? boo$&ist D new Pector:=? boo$&ist D shoppingCart.getContents:=? enum D boo$&ist.elements:=? while:enum.hasMore#lements:== @ 5tring title D :5tring=enum.ne3t#lement:=? 5ystem.out.println:title=? A 5ystem.out.println:ESn o C want to remove any boo$ from cartE=? 5tring ch D br.read&ine:=? if:ch.eLuals:EyE== @ try @ 5ystem.out.println:E#nter the boo$ nameE=? 5tring remBoo$ D br.read&ine:=? shoppingCart.removeBoo$:remBoo$=? 5ystem.out.println:ESnBoo$ has been removed from the cartE=? 5ystem.out.println:ECustomer nmaeF EGcust=? 5ystem.out.println:E5lected boo$s are listed belowE=? boo$&ist D shoppingCart.getContents:=? enum D boo$&ist.elements:=? 12

while:enum.hasMore#lements:== @ 5tring title1 D :5tring=enum.ne3t#lement:=? 5ystem.out.println:title1=? A 5ystem.out.println:E0han$s for dealing with usE=? A catch:#3ception e3= @ 5ystem.out.println:Ecaught a Boo$#3ception E Ge3.getMessage:==? A A else 5ystem.out.println:Ethan$s for dealing with usE=? shoppingCart.remove:=? A catch:#3ception e3= @ 5ystem.out.println:ECaught a Boo$ #3ceptionE=? e3.print5tac$0race:=? A A A

1"

E+(No ! 8

De0elopin- an Enterpri*e Ja0a 'ean for ban6in- operation*

Aim ! 0o develop an #nterprise Java Bean for ban$ing operations Al-ort)m ! 1. Create four programs) Ban$bean9 Ban$home9 Ban$9 and Ban$client 2. In the Ban$bean class first define the prototypes of the various methods ". /e3t9 provide the implementation for e>bCreate:=9 e>bKostCreate:=9 credit:=9 and debit:= methods %. In the Ban$home class >ust invo$e the methods create:= and findbyprimary$ey:= with the respective number of arguments '. In the Ban$remote class >ust define the prototypes of the various methods which throws the Remotee3ception ,. In the Ban$client class9 display the options to the user and use the loo$up:= method and perform the operations accordingly .ro-ram 'an67Remote Interface import >ava3.e>b.B? import >ava.rmi.B? import >ava.util.B? public interface Ban$Remote e3tends #JB-b>ect @ public Integer getCusid:= throws Remote#3ception? public void setBal:double balance= throws Remote#3ception? public double getBal:= throws Remote#3ception? public void debit:double amount= throws Remote#3ception? public void credit:double amount= throws Remote#3ception? A 'an67Home interface import >ava.io.B? import >ava.rmi.Remote#3ception? import >ava3.e>b.B?

1%

public interface Ban$Qome e3tends #JBQome @ public Ban$Remote create:Integer empid9double balance= throws Remote#3ception9Create#3ception? public Ban$Remote findByKrimary!ey:Integer cusid= throws +inder#3ception9Remote#3ception? A 'an67'ean cla** import >ava3.rmi.B? import >ava3.e>b.B? public abstract class Ban$Bean implements #ntityBean @ public double cbalance? public double amount? public double balance? public #ntityConte3t conte3t9ct3? public Integer id? public void e>b(ctivate:= @A public void e>bKassivate:= @A public void e>bRemove:= @A public void e>b&oad:=@A public void e>b5tore:=@A public void set#ntityConte3t:#ntityConte3t ct3= @A public void unset#ntityConte3t:= @A public abstract void setCusid:Integer cusid=? public abstract Integer getCusid:=? public abstract void setBal:double balance=? public abstract double getBal:=? public Integer e>bCreate:Integer cusid9double balance= @ setCusid:cusid=? setBal:balance=? return null? A public void e>bKostCreate:Integer cusid9double balance=@A public void debit:double amount= @ balance D getBal:=? balance)D amount? setBal:balance=? A public void credit:double amount= @ balance D getBal:=?

1'

balanceGDamount? setBal:balance=? A A 'an6 Client import >ava3.naming.B? import >ava3.rmi.B? import >ava.rmi.B? import >ava.io.B? import >ava.util.B? import >ava3.e>b.B? public class Ban$Client @ public static void main:5tring arg;<= @ int cid? double cbalance? int ch? double camount? try @ Kroperties p D new Kroperties:=? p.put:Conte3t.I/I0I(&TC-/0#*0T+(C0-RU9 Eweblogic.>ndi.7&InitialConte3t+actoryE=? p.put:Conte3t.KR-PI #RTCR&9 Et"F..localhostF1661E=? p.put:Conte3t.5#CCRI0UTKRI/CIK(&9ErecE=? p.put:Conte3t.5#CCRI0UTCR# #/0I(&59 EmcastudentE=? InitialConte3t ict D new InitialConte3t:p=? 5ystem.out.println:EConte3t sucessfulE=? -b>ect t D ict.loo$up:EBan$Bean1E=? 5ystem.out.println:E&oo$up successfulE=? Ban$Qome h D :Ban$Qome=KortableRemote-b>ect.narrow:t9Ban$Qome.class=? 5ystem.out.println:EQome stub obtainedE=? try @ 5ystem.out.println:ESn 1.CR#(0# Sn2. CR# I0 Sn". #BI0 Sn%. B(&(/C# Sn'. #*I0E=? BufferedReader br D new BufferedReader:new Input5treamReader:5ystem.in==? chDInteger.parseInt:br.read&ine:==? switch:ch= @ case 1F 5ystem.out.println:ESn#nter the account numberF E=?

1,

cid D Integer.parseInt:br.read&ine:==? 5ystem.out.println:ESn#nter Initial amountF E=? camount D Integer.parseInt:br.read&ine:==? Ban$Remote e D h.create:new Integer:cid=9camount=? 5ystem.out.println:E5uccessfully insertedE=? brea$? case 2F 5ystem.out.println:ESn#nter the account numberF E=? cid D Integer.parseInt:br.read&ine:==? Ban$Remote c D h.findByKrimary!ey:new Integer:cid==? 5ystem.out.println:ESn#nter the amountF E=? camount D Integer.parseInt:br.read&ine:==? c.credit:camount=? cbalance D c.getBal:=? 5ystem.out.println:E(vailable balanceF EGcbalance=? brea$? case "F 5ystem.out.println:ESn#nter the account numberF E=? cid D Integer.parseInt:br.read&ine:==? Ban$Remote d D h.findByKrimary!ey:new Integer:cid==? 5ystem.out.println:ESn#nter the amountF E=? camount D Integer.parseInt:br.read&ine:==? d.debit:camount=? cbalance D d.getBal:=? 5ystem.out.println:E(vailable balanceF EGcbalance=? brea$? case %F 5ystem.out.println:ESn#nter the account numberF E=? cid D Integer.parseInt:br.read&ine:==? Ban$Remote b D h.findByKrimary!ey:new Integer:cid==? cbalance D b.getBal:=? 5ystem.out.println:E(vailable balanceF EGcbalance=? brea$? A A catch:I-#3ception e= @ 5ystem.out.println:E#3ception invo$edE=? A catch:#3ception e= @ 5ystem.out.println:EInvalid Customer I E=? A A catch:#3ception e3= @ e3.print5tac$0race:=? A AA

11

E+(No !$

Create an Acti0e79 control for /ile operation*


ocument an perform t)e 0ariou* file

Aim ! :o e0elop an Acti0e+ control operation* on it( Al-ort)m !

1. Create a new (ctive3 control document in Pisual Basic 2. (dd the drive list9 directory list and file list controls from the toolbo3 ". (lso add three te3tbo3es correspondingly %. Clic$ on +ile )N ma$e pro>ect1. oc3 and specify the reLuired name and location '. ouble clic$ on each control to add the respective coding ,. clic$ on debug)N start to e3ecute the application

.ro-ram
FILE OPERATIONS USING ACTIVEX CONTROL Krivate 5ub ir1TChange:= +ile1.Kath D ir1.Kath #nd 5ub Krivate 5ub rive1TChange:= ir1.Kath D rive1. rive #nd 5ub Krivate 5ub +ile1TClic$:= 0e3t1.0e3t D +ile1.Kath #nd 5ub Krivate 5ub ir1TClic$:= 0e3t2.0e3t D ir1.+ont/ame 0e3t".0e3t D ir1.&istInde3 #nd 5ub

12

Ex.No: 6 Aim:

COMPONENT SIMULATING CURRENCY CONVERSION

To write a program in C# to perform conversion of dollars to rupees. Algorithm: ALGORITHM FOR COMPONENT. St ! ": Create a namespace as currwithcomp. St ! #: Create a class called currency as public. St ! $: Inside the class declare the private variables x of type integer. St ! %: Define a property variables x. St ! &: In the property we have the get and set method. St ! 6: Get method is used to get the value form the user and set is used for setting the user value to the original variables. St ! ': Define a method called doll( as public. St ! '.": !eturn the value of x " #$. St ! '.#: %nd of the method. St ! (: %nd of the component. AGORITHM FOR MAIN. St ! ": Create a class called curr. St ! #: Define the main function. St ! #.": Create an ob&ect ob for currency. St ! #.# : Get the value of x using Console.!eadline( method. St ! #.$: 'rint the converted value using Console.(riteline( method. St ! #.%: %nd of the main. Progr)m: COMPONENT using )ystem* namespace CompC) + public class Conv + private int i,-.&,#/* public int varI

14

+ get+return i*0 set+i,value*0 0 public int sum( + return i"&* 0 0 0 MAIN using )ystem* using CompC)* class ConvertComp + public static void 1ain( + Conv ob& , new Conv( * Console.(rite2ine(3%nter the dollar amount u want to convert43 * int x , int.'arse(Console.!ead2ine( * ob&.varI , x* Console.(rite2ine(3Dollar value 4 +-03.ob&.varI * Console.(rite2ine(3!uppes value 4 +-03.ob&.sum( * 0 0 Ex *+tio, St !-: 5.Create a dll file for the component csc 6target4library Convert.cs 7.Create an exe file for the main csc 6reference4Convert.dll ConvertComp.cs 8.!un the exe file ConvertComp O+t!+t: %nter the dollar amount u want to convert48Dollar value 4 8-

26

!uppes value 4 58/-

CONVERTING THE CURRENCY VALUES USING COM

C- I/O5 +-R BC55I/#55 &(U#R BBBBBBBBBBBBBBBBBBBBBBBBBBB Kublic Class Class1 Kublic +unction cur1:ByPal c1 (s 5tring= (s 5tring cur1 D c1 B %".%% MsgBo3:cur1= #nd +unction Kublic +unction cur2:ByPal c2 (s 5tring= (s 5tring cur2 D c2 B '1.16' MsgBo3:cur2= #nd +unction Kublic +unction cur":ByPal c" (s 5tring= (s 5tring cur" D c" B 11%.1" MsgBo3:cur"= #nd +unction Kublic +unction cur%:ByPal c% (s 5tring= (s 5tring cur% D c% B 12.62% MsgBo3:cur%= #nd +unction Kublic +unction cur':ByPal c' (s 5tring= (s 5tring cur' D c' B 1.,,2" MsgBo3:cur'= #nd +unction #nd Class 21

C- I/O5 +-R KR#5#/0(0I-/ &(U#R BBBBBBBBBBBBBBBBBBBBBBBBBBBBBB Kublic Class +orm1 im ob> (s /ew class&ibrary1.class1 Krivate 5ub Button1TClic$:ByPal sender (s 5ystem.-b>ect9 ByPal e (s 5ystem.#vent(rgs= Qandles Button1.Clic$ If :ComboBo31.0e3t D ECsa ollerE= 0hen im s D Pal:0e3tBo31.0e3t= ob>.cur1:s= #lseIf :ComboBo31.0e3t D E#urroE= 0hen im s D Pal:0e3tBo31.0e3t= ob>.cur2:s= #lseIf :ComboBo31.0e3t D E-man RialE= 0hen im s D Pal:0e3tBo31.0e3t= ob>.cur":s= #lseIf :ComboBo31.0e3t D ECae irhamE= 0hen im s D Pal:0e3tBo31.0e3t= ob>.cur%:s= #lseIf :ComboBo31.0e3t D ERussian RoubleE= 0hen im s D Pal:0e3tBo31.0e3t= ob>.cur':s= #nd If #nd 5ub #nd Class

22

Ex.No: ' Aim:

COMPONENT SIMULATING ENCRYPRION AN. .ECRYPTION

To write a C# program to perform encryption and decryption of the given data. Algorithm ALGORITHM FOR ENCRYPTION: St ! ": St ! #: St ! $: type. St ! %: Declare the class as encrypt9class. )tart the main function. Declare the variable str in string data

Create the ob&ect for inbuild encryption algorithm TripleD%)Crypto)ervice'rovider. St ! &: Create the data file using :ilestream class. St ! 6: Create the ob&ect for class crypto)tream. Cryptostream is a class to invo;e the %ncryotor algorithm. Get the input from the user using Console.!eadline( . St ! ': (rite the input data using (rite2ine function. St ! (: Create the ;ey file using :ile.Create. St ! /: convert the ;ey file into binary form. St ! "0:Close the file. St ! "":'rint Data encrypted using console.write2ine.

ALGORITHM FOR .ECRYPTION : St ! ": Declare a class as decrypt9class St ! #: start the main function St ! $:Create the ob&ect for the inbuild algorithm TripleD%)Crypotservice'rovider. St ! %: Create the file in c drive using :ile)tream fs ,:ile.open!ead. St ! &: <sing =inary !eader convert file as in

2"

binary form. St ! 6:!ead the number of bytes of ;ey file. St ! ': >pen the data file using :ile!ead function. St ! (: Cryptostream is a class to use invo;e the Decrytptor. St ! /: Create the ob&ect for Crypto)tream class. St ! "0: <sing )tream!eader read the data file . St ! "": 'rint the content of data file using Console.write2ine. St ! "#: Close the file.

Progr)m: E,*r1!tio, using )ystem* using )ystem.I>* using )ystem.)ecurity.Cryptography* class encrypt9class + public static void 1ain( + )tring str* TripleD%)Crypto)ervice'rovider cp, new TripleD%)Crypto)ervice'rovider( * :ile)tream fs , :ile.Create(3C4??file.dat3 * Crypto)tream cs , new Crypto)tream(fs.cp.Create%ncryptor( .Crypto)tream1ode.(rite * )tream(riter sw , new )tream(riter(cs * Console.(rite2ine(3%nter a string3 * str,Console.!ead2ine( * sw.(rite2ine(str * sw.Close( * fs, :ile.Create(3C4??file.;ey3 *

2%

=inary(riter bw , new =inary(riter(fs * bw.(rite(cp.@ey * bw.(rite(cp.IA * bw.Close( * Console.(rite2ine(3Data %ncrypted........3 * 0 0 . *r1!tio,: using )ystem* using )ystem.I>* using )ystem.)ecurity.Cryptography* class decrypt9class + public static void 1ain( + TripleD%)Crypto)ervice'rovider cp, new TripleD%)Crypto)ervice'rovider( * :ile)tream fs , :ile.>pen!ead(3C4??file.;ey3 * =inary!eader br , new =inary!eader(fs * cp.@ey,br.!ead=ytes(7# * cp.IA,br.!ead=ytes(B * fs, :ile.>pen!ead(3C4??file.dat3 * Crypto)tream cs , new Crypto)tream(fs.cp.CreateDecryptor( .Crypto)tream1ode.!ead * )tream!eader sr , new )tream!eader(cs * Console.(rite2ine(3Content in the file (Cfter Decryption 3 * Console.(rite2ine(sr.!ead2ine( * sr.Close( * 0 0 Ex *+tio,: csc encrypt9class.cs encrypt9class file %nter the string

2'

Cbcdefghi&;lmnopDrstuvwxyE Data encryptedFF csc decrypt9class.cs decrypt9class file Content in the file is (Cfter decryption Cbcdefghi&;lmnopDrstuvwxyE. ENCRYPTION AND DECRYPTION PROGRAM USING COM im dstr (s 5tring im i (s Integer Krivate 5ub Button2TClic$:ByPal sender (s 5ystem.-b>ect9 ByPal e (s 5ystem.#vent(rgs= Qandles Button2.Clic$ +or i D 1 0o &en:0e3tBo31.0e3t= dstr D dstr G Chr:(sc:Mid:0e3tBo31.0e3t9 i9 1== G i= /e3t 0e3tBo31.0e3t D dstr #nd 5ub

Krivate 5ub Button1TClic$:ByPal sender (s 5ystem.-b>ect9 ByPal e (s 5ystem.#vent(rgs= Qandles Button1.Clic$ dstr D EE +or i D &en:0e3tBo31.0e3t= 0o 1 5tep )1 dstr D Chr:(sc:Mid:0e3tBo31.0e3t9 i9 1== ) i= G dstr /e3t 0e3tBo31.0e3t D dstr #nd 5ub 2 evelop a middleware component for retrieving 5toc$ Mar$et #3change information using C-RB( 2,

5toc$ Mar$et.idl module 5imple5toc$s@ interface 5toc$Mar$et @ float getTprice:in string symbol=? A? A? 5toc$Mar$etClient.>ava import org.omg.C-RB(.B? import org.omg.Cos/aming.B? import 5imple5toc$s.B? public class 5toc$Mar$etClient @ public static void main:5tring;< args= @ try @ -RB orbD-RB.init:args9null=? /amingConte3t ncRefD/amingConte3tQelper.narrow:orb.resolveTinitialTreferences:E/ame5erviceE==? /ameComponent path;<D@new /ameComponent:E/(5 (VE9EE=A? 5toc$Mar$et mar$etD5toc$Mar$etQelper.narrow:ncRef.resolve:path==? 5ystem.out.println:EKrice of My company isEGmar$et.getTprice:EMyTC-MK(/UE==? A catch:#3ception e=@ e.print5tac$0race:=? A A A 5toc$Mar$etImpl import org.omg.C-RB(.B? import 5imple5toc$s.B? public class 5toc$Mar$etImpl e3tends T5toc$Mar$etImplBase @ public float getTprice:5tring symbol= @ float priceD6? for:int iD6?iMsymbol.length:=?iGG=

21

@ priceGD:int=symbol.char(t:i=?A price.D'? return price? A public 5toc$Mar$etImpl:=@super:=?A A 5toc$Mar$et5erver import org.omg.C-RB(.B? import org.omg.Cos/aming.B? import 5imple5toc$s.B? public class 5toc$Mar$et5erver @ public static void main:5tring;< args= @ try @ -RB orbD-RB.init:args9null=? 5toc$Mar$etImpl stoc$Mar$etImplDnew 5toc$Mar$etImpl:=? orb.connect:stoc$Mar$etImpl=? org.omg.C-RB(.-b>ect ob>RefDorb.resolveTinitialTreferences:E/ame5erviceE=? /amingConte3t ncRefD/amingConte3tQelper.narrow:ob>Ref=? /ameComponent ncDnew /ameComponent:E/(5 (VE9EE=? /ameComponent path;<D@ncA? ncRef.rebind:path9stoc$Mar$etImpl=? 5ystem.out.println:E5toc$Mar$et server is readyE=? 0hread.current0hread:=.>oin:=? A catch:#3ception e=@ e.print5tac$0race:=? A A A

#*#CC0I-/ 50#K5 1.cR#(0# ( I/0#R+(C#:idl9CKK=

22

2.Create IMK&#M#/0(0I-/ KR-OR(M ".s#RP#R KR-OR(M %.Client program '.c-MM(/ idlto>ava )fno)cpp interfacename.idl >avac servant >avac server >avac client tnameserv )-RBInitialKort 466 >ava Qello5erver in another window cmd >ava 5toc$Mar$etClient

"0.

COMMUNICATION 2ET3EEN CLIENT AN. SERVER USING COR2A

Aim: To write a program to print GHello (orldI in C>!=C. Algorithm: St ! ": )tart the process St ! #: Create an idl class in a module Hello5and declare a method sayHello( . St ! $: Create an implement class HelloImpl which extends 9HelloImpl=ase and import the module. St ! %: Define the sayHello method and return the result. St ! &: Define the client program named HelloClient which imports the module 4i5 Declare a static reference for interface Hello 4ii5 Create and initialiEe the >!= and get the root naming context. 4iii5 !esolve the >b&ect !eference in Jaming. 4i65 Call the sayHello method St ! 6: 4i5 4ii5 4iii5 4i65 Create the Hello)erver which imports the module. Create and initialiEe the >!=. Create servant and register it with the >!=. Get ob&ect reference from the servant. =ind the >b&ect !eference in Jaming. 24

465 <se JamingContext. 46i5 (ait for invocations from clients St ! ': )top the process. Progr)m Co7 : I.L Cl)--:8 module Hello5 + interface Hello + string sayHello( * 0* 0* Cli ,t Cl)--:8 import Hello5."* import org.omg.CosJaming."* import org.omg.CosJaming.JamingContext'ac;age."* import org.omg.C>!=C."* public class HelloClient + static Hello helloImpl* public static void main()tring argsKL + try + 66 create and initialiEe the >!= >!= orb , >!=.init(args. null * 66 get the root naming context org.omg.C>!=C.>b&ect ob&!ef , orb.resolve9initial9references(3Jame)ervice3 * JamingContext nc!ef , JamingContextHelper.narrow(ob&!ef * 66 resolve the >b&ect !eference in Jaming JameComponent nc,new JameComponent (3Hello3.33 * JameComponent pathKL , +nc0* helloImpl , HelloHelper.narrow(nc!ef.resolve(path * )ystem.out.println(helloImpl.sayHello( 0 catch (%xception e + )ystem.out.println(3%!!>! 4 3 M e *

"6

0 0 0 Im!l m ,t Cl)--: import Hello5."* import org.omg.CosJaming."* import org.omg.CosJaming.JamingContext'ac;age."* import org.omg.C>!=C."* import &ava.util.'roperties* class HelloImpl extends 9HelloImpl=ase + 66 implement sayHello( method public )tring sayHello( + return 3?nHello world NN?n3* 0 0

S r6 r Cl)--:8 import import import import Hello5."* org.omg.CosJaming."* org.omg.CosJaming.JamingContext'ac;age."* org.omg.C>!=C."*

public class Hello)erver + public static void main()tring argsKL + try + 66 create and initialiEe the >!= >!= orb , >!=.init(args. null * 66 create servant and register it with the >!= HelloImpl helloImpl , new HelloImpl( * orb.connect(helloImpl * 66 get ob&ect reference from the servant org.omg.C>!=C.>b&ect ob&!ef ,orb.resolve9initial9references(3Jame)ervice3 * 66 <se JamingContext JamingContext nc!ef , JamingContextHelper.narrow(ob&!ef * 66 bind the >b&ect !eference in Jaming

"1

JameComponent nc,new JameComponent (3Hello3.33 * JameComponent pathKL , +nc0* nc!ef.rebind(path. helloImpl * )ystem.out.println(3Hello)erver ready and waiting ...3 * 66 wait for invocations from clients orb.run( * 0 catch (%xception e + )ystem.err.println(3%!!>!4 3 M e * 0 )ystem.out.println(3Hello)erver %xiting ...3 * 0 0 O+t!+t: Im!l Si7 : O4?1iddle ware?corba5Pidl& Qfclient Qfserver Qimpl=ase hello.idl O4?1iddle ware?corba5Pcd hello5 O4?1iddle ware?corba5?Hello5P&avac ".&ava O4?1iddle ware?corba5Ptnameserv Initial Jaming Context4 I>!4--------------7B#R###c8a$f$d$S7e$fS7$S7f#8$fS8#e$5 $d$R$e$S7f#e$5$d$R$e $S#8$f$eS#$/SBS#8a857e8----------5--------------/#---5 -5---------d858S87 7e858$7e857e858-8B-----#5f------5Bafabcafe-------7/B#b 7S5b-------B----------------------5-------5------5#-----------5--7-----------5-5--------TransientJame)erver4 setting port for initial ob&ect references to4 R-!eady. S r6 r Si7 : O4?1iddle ware?corba5P&avac ".&ava O4?1iddle ware?corba5P&ava Hello)erver H lloS r6 r r )71 ),7 9)iti,g... Cli ,t Si7 : O4?1iddle ware?corba5P&ava HelloClient

"2

H llo 9orl7::

""

Вам также может понравиться