Vous êtes sur la page 1sur 49

Ex.

No: 1 Aim:

DOWNLOAD FILES FROM VARIOUS SERVER USING RMI

To create a distributed application to download various files from various servers using RMI Algorithm: STEP 1: Create four files file interface, file implementation, file client and fileserver. STEP 2: In the file interface, class specifies the prototype of the method that is to be STEP 3: Implemented in the file implementation class. STEP 4: In the file implementation class, specify the implementation coding for the STEP 5: Method defined earlier (download file[]). STEP 6: Try to read the contents of a file in this class. STEP 7: In the fileclient class try to write some contents into a file. STEP 8: In the fileserver class, try to register / bind the methods with the rmiregistry. STEP 9: Compile all the files and execute as specified to get the desired output. Program FileInterface.java import java.rmi.Remote; import java.rmi.RemoteException; public interface FileInterface extends Remote { public byte[] downloadFile(String fileName) throws RemoteException; } FileImpl.java import java.io.*; import java.rmi.*; import java.rmi.server.UnicastRemoteObject;

public class FileImpl extends UnicastRemoteObject implements FileInterface { private String name; public FileImpl(String s) throws RemoteException{ super(); name = s; } public byte[] downloadFile(String fileName){ try { File file = new File(fileName); byte buffer[] = new byte[(int)file.length()]; BufferedInputStream input = new BufferedInputStream(new FileInputStream(fileName)); input.read(buffer,0,buffer.length); input.close(); return(buffer); } catch(Exception e){ System.out.println("FileImpl: "+e.getMessage()); e.printStackTrace(); return(null); } } } FileServer.java import java.io.*; import java.rmi.*; public class FileServer { public static void main(String argv[]) { 2

try { FileInterface fi = new FileImpl("FileServer"); Naming.rebind("//127.0.0.1/FileServer", fi); } catch(Exception e) { System.out.println("FileServer: "+e.getMessage()); e.printStackTrace(); } } } FileClient.java import java.io.*; import java.rmi.*; public class FileClient{ public static void main(String argv[]) { if(argv.length != 2) { System.out.println("Usage: java FileClient fileName machineName"); System.exit(0); } try { String name = "//" + argv[1] + "/FileServer"; FileInterface fi = (FileInterface) Naming.lookup(name); byte[] filedata = fi.downloadFile(argv[0]); System.out.println(enter the file to download); BufferedReader br = new BufferedReader(new InputStreamReader(system.in)); String newname = br.readLine(); File file = new File(newname); BufferedOutputStream output = new BufferedOutputStream(new FileOutputStream(file.getName())); output.write(filedata,0,filedata.length);

output.flush(); output.close(); } catch(Exception e) { System.err.println("FileServer exception: "+ e.getMessage()); e.printStackTrace(); } } }

Execution Server folder [interface.java,fileimpl.java,file server.java] 1. Compile all the java program using (javac filename.java) 2. enter the (start rmiregistry) in command line 3. create stub and skeleton using (rmic FileImpl) 4.create one file i.e a.txt in server folder 5. Run the server using (java FileServer) Client folder[file interface.java,fileclient.java,copy the stub and skeleton from server folder and paste it in client folder] 1. Compile all the java program using (javac filename.java) (The next contains two parameters First is the text file created by the user second is machine IP Address) 2. Run the Client using (java FileClient a.txt 192.168.0.154) 3. next step you will give the file name to download the file (Enter the file name to download : b.txt) 4. a.txt and b.txt contains the same content.

Result: Thus the program to download the various files from server using rmi was performed successfully. 5

Ex.No: 2

CREATE A JAVA BEAN TO DRAW VARIOUS GRAPHICAL SHAPES USING BDK OR WITHOUT BDK

Aim: To create a Java Bean to draw various graphical shapes and display it using or without using BDK. Algorithm: STEP 1: Create a class shapes which extends Applet superclass and which implements ActionListener interface. STEP 2: Create list,label,font with the required captions and add them to the container. STEP 3: Register the list with the ActionListener interface. STEP 4: In the Actionperformed () method, with the help of the instance, performs the action respectively. STEP 5: In the paint() method, check which button is pressed and display the shapes accordingly. Program import java.awt.*; import java.applet.*; import java.awt.event.*; /*<applet code="shapes" width=400 height=400></applet>*/ public class shapes extends Applet implements ActionListener { List list; Label l1; Font f; public void init() { Panel p1=new Panel(); Color c1=new Color(255,100,230);

setForeground(c1); f=new Font("Monospaced",Font.BOLD,20); setFont(f); l1=new Label("D R A W I N G V A R I O U S G R A P H I C A L S H A P E S",Label.CENTER); p1.add(l1); add(p1,"NORTH"); Panel p2=new Panel(); list=new List(3,false); list.add("Line"); list.add("Circle"); list.add("Ellipse"); list.add("Arc"); list.add("Polygon"); list.add("Rectangle"); list.add("Rounded Rectangle"); list.add("Filled Circle"); list.add("Filled Ellipse"); list.add("Filled Arc"); list.add("Filled Polygon"); list.add("Filled Rectangle"); list.add("Filled Rounded Rectangle"); p2.add(list); add(p2,"CENTER"); list.addActionListener(this); } public void actionPerformed(ActionEvent ae) { repaint(); }

public void paint(Graphics g) { int i; Color c1=new Color(255,120,130); Color c2=new Color(100,255,100); Color c3=new Color(100,100,255); Color c4=new Color(255,120,130); Color c5=new Color(100,255,100); Color c6=new Color(100,100,255); if (list.getSelectedIndex()==0) { g.setColor(c1); g.drawLine(150,150,200,250); } if (list.getSelectedIndex()==1) { g.setColor(c2); g.drawOval(150,150,190,190); } if (list.getSelectedIndex()==2) { g.setColor(c3); g.drawOval(290,100,190,130); } if (list.getSelectedIndex()==3) { g.setColor(c4); g.drawArc(100,140,170,170,0,120); } if (list.getSelectedIndex()==4) {

g.setColor(c5); int x[]={130,400,130,300,130}; int y[]={130,130,300,400,130}; g.drawPolygon(x,y,5); } if (list.getSelectedIndex()==5) { g.setColor(Color.cyan); g.drawRect(100,100,160,150); } if (list.getSelectedIndex()==6) { g.setColor(Color.blue); g.drawRoundRect(190,110,160,150,85,85); } if (list.getSelectedIndex()==7) { g.setColor(c2); g.fillOval(150,150,190,190); } if (list.getSelectedIndex()==8) { g.setColor(c3); g.fillOval(290,100,190,130); } if (list.getSelectedIndex()==9) { g.setColor(c4); g.fillArc(100,140,170,170,0,120); } if (list.getSelectedIndex()==10)

{ g.setColor(c5); int x[]={130,400,130,300,130}; int y[]={130,130,300,400,130}; g.fillPolygon(x,y,5); } if (list.getSelectedIndex()==11) { g.setColor(Color.cyan); g.fillRect(100,100,160,150); } if (list.getSelectedIndex()==12) { g.setColor(Color.blue); g.fillRoundRect(190,110,160,150,85,85); } } }

Output: G:\programs>cd dsi G:\programs\DSI>cd shapes G:\programs\DSI\shapes>path=d:/jdk1.5/bin G:\programs\DSI\shapes>set classpath=;.; G:\programs\DSI\shapes>javac shapes.java G:\programs\DSI\shapes> appletviewer shapes.java

10

Output:

Result: Thus the program to draw the various shapes without using bdk was created successfully. 11

Ex.No : 3 Aim:

Developing an Enterprise Java Bean for banking operations

To develop an Enterprise Java Bean for banking operations. Algorithm: STEP 1: Create four programs- atmbean, atmhome, atm, and atmclient. STEP 2: In the atmbean class first define the prototypes of the various methods. STEP 3: Next, provide the implementation for ejbCreate(), ejbPostCreate(), credit(), and debit() methods. STEP 4: In the atmhome class just invoke the methods create() and findbyprimarykey() with the respective number of arguments. STEP 5: In the atmremote class just define the prototypes of the various methods which throws the Remoteexception. STEP 6: In the atmclient class, display the options to the user and use the lookup() method and perform the operations accordingly. Program: atmhome.java import javax.ejb.*; import java.io.Serializable; import java.rmi.*; public interface atmhome extends EJBHome { public atmremote create(int accno,String name,String type,float balance)throws RemoteException,CreateException; } atmremote.java. import java.io.Serializable; import javax.ejb.*; import java.rmi.*;

12

public interface atmremote extends EJBObject { public float deposit(float amt) throws RemoteException; public float withdraw(float amt) throws RemoteException; } atm.java import javax.ejb.*; import java.rmi.*; public class atm implements SessionBean { int acno; String name1; String tt; float bal; public void ejbCreate(int accno,String name,String type,float balance) { acno=accno; name1=name; tt=type; bal=balance;} public float deposit(float amt) { return(bal+amt); } public float withdraw(float amt) { return(bal-amt); } public atm() {}

13

public void ejbRemove(){} public void ejbActivate(){} public void ejbPassivate(){} public void setSessionContext(SessionContext sc){} } atmclient.java import javax.rmi.*; import java.util.*; import javax.naming.Context; import javax.naming.InitialContext; import javax.rmi.PortableRemoteObject; import java.util.*; import java.io.*; import java.net.*; import javax.naming.NamingException; import java.rmi.RemoteException; import javax.ejb.CreateException; import java.util.Properties; public class atmclient { public static void main(String args[]) throws Exception { float bal=0; String tt=" "; Properties props = new Properties(); props.setProperty(InitialContext.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInit ialContextFactory"); props.setProperty(InitialContext.PROVIDER_URL, "t3://localhost:7001"); props.setProperty(InitialContext.SECURITY_PRINCIPAL,""); props.setProperty(InitialContext.SECURITY_CREDENTIALS," ");

14

InitialContext initial = new InitialContext(props); Object objref = initial.lookup("atm2"); atmhome home = (atmhome)PortableRemoteObject.narrow(objref,atmhome.class); BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int ch=1; String name; int acc; System.out.println("Enter the Details"); System.out.println("Enter the Account Number:"); acc=Integer.parseInt(br.readLine()); System.out.println("Enter Ur Name:"); name=br.readLine(); while(ch<=4) { System.out.println("\t\tBANK OPERATIONS"); System.out.println("\t\t***************"); System.out.println(""); System.out.println("\t\t1.DEPOSIT"); System.out.println("\t\t2.WITHDRAW"); System.out.println("\t\t3.DISPLAY"); System.out.println("\t\t4.EXIT"); System.out.println("\t\tENTER UR OPTION:"); ch=Integer.parseInt(br.readLine()); switch(ch) { case 1: System.out.println("Enter the Transaction type;"); tt=br.readLine(); atmremote bb= home.create(acc,name,tt,10000); System.out.println("Entering"); System.out.println("Enter the transaction amt:");

15

float amt=Float.parseFloat(br.readLine()); bal=bb.deposit(amt); System.out.println("Balance after deposit=" +bal); break; case 2: System.out.println("Enter the Transaction type;"); tt=br.readLine(); bb= home.create(acc,name,tt,bal); System.out.println("Entering"); System.out.println("Enter the transaction amt:"); amt=Float.parseFloat(br.readLine()); bal=bb.withdraw(amt); System.out.println("Balance after withdraw" + bal); break; case 3: System.out.println("Status of the Customer"); System.out.println("Account Number:"+acc); System.out.println("Name of the Customer:"+name); System.out.println("Transaction type:"+tt); System.out.println("Balance"+bal); break; case 4: System.exit(0); } //switch }//while }//main }//class Output: G:\program\EJB>cd bank G:\program\EJB\bank>path=c:\bean\jdk141_03\bin

16

G:\program\EJB\bank>set classpath=%classpath%;;c:\bean\weblogic81\server\weblogic.jar G:\program\EJB\bank>javac *.java G:\program\EJB\bank>cd cli G:\program\EJB\bank\cli> path=c:\bean\jdk141_03\bin G:\program\EJB\bank\cli> set classpath=%classpath %;;c:\bean\weblogic81\server\weblogic.jar G:\program\EJB\bank\cli> javac *.java G:\program\EJB\bank\cli>jar cvf atm.jar *.class Added manifest Adding:atmhome.class(in=277)(out=192)(deflate 30%) Adding:atmhome.class(in=233)(out=176)(deflate 24%) Start weblogic server Deploying modules G:\program\EJB\bank\cli>java atmclient Enter details Enter the account number: 125 Enter ur name: Sasi BANK OPERATIONS ***************** 1.DEPOSIT 2.WITHDRAW 3.DISPLAY 4.EXIT Enter your option: 1 Enter the transaction Type: Savings Enter the Transaction Amount:

17

1000 Balance after Deposit=11000.00

Result: Thus the enterprise java bean program for banking operations was developed and performed successfully. Ex.No : 4 Developing an Enterprise Java Bean for Library operations

18

Aim: To develop an Enterprise Java Bean for Library operations. Algorithm: STEP 1: Create five programs library, librarybome, librarybean, libraryexception, and libraryclient. STEP 2: In the libraryhome class just invoke the create() method with appropriate arguments. STEP 3: In the library class, just define the prototytpes of addbook(), removebook() and getcontents() methods. STEP 4: In the librarybean class provide the implementation for the various methods. STEP 5: In the libraryexception class provide the implementation for libraryException. STEP 6: In the libraryclient class get the customer name and the various books he wants, also perform the other operations accordingly. Program: libraryhome.java import javax.ejb.*; import java.io.Serializable; import java.rmi.*; public interface libraryhome extends EJBHome { public libraryremote create(int id,String title,String author,int nc)throws RemoteException,CreateException; } libraryremote.java import java.io.Serializable; import javax.ejb.*; import java.rmi.*; public interface libraryremote extends EJBObject { public boolean issue(int id,String title,String author,int nc) throws RemoteException;

19

public boolean receive(int id,String title,String author,int nc) throws RemoteException; public int ncpy() throws RemoteException; } library.java import javax.ejb.*; import java.rmi.*; public class library implements SessionBean { int bkid; String tit; String auth; int nc1; boolean status=false; public void ejbCreate(int id,String title,String author,int nc) { bkid=id; tit=title; auth=author; nc1=nc; } public int ncpy() { return nc1; } public boolean issue(int id,String tit,String auth,int nc) { if(bkid==id) nc1--; status=true; else { } } { status=false; return(status); if(bkid==id) } {

public boolean receive(int id,String tit,String auth,int nc) {

20

nc1++; status=true; else { } status=false; return(status); } public void ejbRemove(){} public void ejbActivate(){} public void ejbPassivate(){} public void setSessionContext(SessionContext sc){} } libraryclient.java import javax.rmi.*; import java.util.*; import javax.naming.Context; import javax.naming.InitialContext; import javax.rmi.*; import java.util.*; import java.io.*; import java.net.*; import javax.naming.*; import java.rmi.RemoteException; import javax.ejb.CreateException; import java.util.Properties; public class libraryclient { public static void main(String args[]) throws Exception { Properties props = new Properties(); Props.setProperty(InitialContext.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInit ialContextFactory"); props.setProperty(InitialContext.PROVIDER_URL, "t3://localhost:7001"); props.setProperty(InitialContext.SECURITY_PRINCIPAL,""); props.setProperty(InitialContext.SECURITY_CREDENTIALS,""); 21 }

InitialContext initial = new InitialContext(props); Object objref = initial.lookup("library2"); libraryhome home= libraryhome)PortableRemoteObject.narrow(objref,libraryhome.class); BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int ch; String tit,auth; int id,nc; boolean st; System.out.println("Enter the Details"); System.out.println("Enter the Account Number:"); id=Integer.parseInt(br.readLine()); System.out.println("Enter The Book Title:"); tit=br.readLine(); System.out.println("Enter the Author:"); auth=br.readLine(); System.out.println("Enter the no.of copies"); nc=Integer.parseInt(br.readLine()); int temp=nc; do { System.out.println("\t\tLIBRARY OPERATIONS"); System.out.println("\t\t***************"); System.out.println(""); System.out.println("\t\t1.ISSUE"); System.out.println("\t\t2.RECEIVE"); System.out.println("\t\t3.EXIT"); System.out.println("\t\tENTER UR OPTION:"); ch=Integer.parseInt(br.readLine()); libraryremote bb= home.create(id,tit,auth,nc); switch(ch) case 1: System.out.println("Entering"); {

22

nc=bb.ncpy(); if(nc>0) { { if(bb.issue(id,tit,auth,nc))

System.out.println("BOOK ID IS:"+id); System.out.println("BOOK TITLE IS:"+tit); System.out.println("BOOK AUTHOR IS:"+auth); System.out.println("NO. OF COPIES :"+bb.ncpy()); nc=bb.ncpy(); System.out.println("Sucess"); break; else System.out.println("Book is not available"); break; case 2: System.out.println("Entering"); if(temp>nc) { System.out.println("temp"+temp); if(bb.receive(id,tit,auth,nc)) { System.out.println("BOOK ID IS:"+id); System.out.println("BOOK TITLE IS:"+tit); System.out.println("BOOK AUTHOR IS:"+auth); System.out.println("NO. OF COPIES :"+bb.ncpy()); nc=bb.ncpy(); System.out.println("Sucess"); break; else System.out.println("Invalid Transaction"); break; case 3: System.exit(0); } //switch } } } }

23

}while(ch<=3 && ch>0); }//main }//class Output: G:\program\EJB>cd library G:\program\EJB\ library >path=c:\bean\jdk141_03\bin G:\program\EJB\ library >set classpath=%classpath %;;c:\bean\weblogic81\server\weblogic.jar G:\program\EJB\ library >javac *.java G:\program\EJB\ library >cd cli G:\program\EJB\ library \cli> path=c:\bean\jdk141_03\bin G:\program\EJB\ library \cli> set classpath=%classpath %;;c:\bean\weblogic81\server\weblogic.jar G:\program\EJB\ library \cli> javac *.java G:\program\EJB\ library \cli>jar cvf library.jar *.class Added manifest Adding: libraryhome.class(in=277)(out=192)(deflate 30%) Adding: libraryhome.class(in=233)(out=176)(deflate 24%) Start weblogic server Deploying modules G:\program\EJB\ library \cli>java libraryclient Enter details Enter the account number: 125 Enter the book title: Mastering in C Enter the author: Balagurusamy LIBRARY OPERATIONS

24

******************** 1. ISSUE 2. RECEIVE 3. EXIT ENTER UR OPTION 3

Result: Thus the enterprise java bean program for library operations was developed and performed successfully. Ex.No :5 Aim: Create an Active-X control for File operations

25

To develop an Active-x control document and perform the various file operations on it. Algorithm: STEP 1: Create a new Active-xx control document in Visual Basic. STEP 2: Add the drive list, directory list and file list controls from the toolbox. STEP 3: Also add three textboxes correspondingly. STEP 4: Click on File -> make project1. ocx and specify the required name and location. STEP 5: Double click on each control to add the respective coding. STEP 6: click on debug-> start to execute the application.

Program:
Public Class Form1 Dim fname As String Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click RichTextBox1.Text = "" End Sub Private Sub btnOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOpen.Click Dim ofile As New OpenFileDialog If ofile.ShowDialog = Windows.Forms.DialogResult.OK Then fname = ofile.FileName RichTextBox1.LoadFile(fname) End If End Sub Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click Dim sfile As New SaveFileDialog If sfile.ShowDialog = Windows.Forms.DialogResult.OK Then fname = sfile.FileName 26

RichTextBox1.SaveFile(fname) End If End Sub Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click Me.Close() End Sub Private Sub RichTextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RichTextBox1.TextChanged End Sub End Class

Output:

27

Result: Thus the above program was successfully created. Ex.No: 6 CONVERTING THE CURRENCY VALUE USING DOT NET Aim:

28

To write a program in C# to perform conversion of dollars to rupees. Algorithm: ALGORITHM FOR COMPONENT. STEP 1: Create a namespace as currwithcomp. STEP 2: Create a class called currency as public. STEP 3: Inside the class declare the private variables x of type integer. STEP 4: Define a property variables x. STEP 5: In the property we have the get and set method. STEP 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. STEP 7: Define a method called doll() as public. STEP 7.1: Return the value of x * 46. STEP 7.2: End of the method. STEP 8: End of the component. AGORITHM FOR MAIN. STEP 1: Create a class called curr. STEP 2: Define the main function. STEP 2.1: Create an object ob for currency. STEP 2.2 : Get the value of x using Console.Readline() method. STEP 2.3: Print the converted value using Console.Writeline() method. STEP 2.4: End of the main. Program: COMPONENT using System; namespace CompCS { public class Conv { 29

private int i=0,j=45; public int varI { get{return i;} set{i=value;} } public int sum() { return i*j; } } }

MAIN using System; using CompCS; class ConvertComp { public static void Main() { Conv obj = new Conv(); Console.WriteLine("Enter the dollar amount u want to convert:"); int x = int.Parse(Console.ReadLine()); obj.varI = x; Console.WriteLine("Dollar value : {0}",obj.varI); Console.WriteLine("Ruppes value : {0}",obj.sum()); } }

30

Execution Steps: 1.Create a dll file for the component csc /target:library Convert.cs 2.Create an exe file for the main csc /reference:Convert.dll ConvertComp.cs 3.Run the exe file ConvertComp

Output: Enter the dollar amount u want to convert:30 Dollar value : 30 Ruppes value : 1350 CONVERTING THE CURRENCY VALUES USING COM CODINGS FOR BUSSINESS LAYER *************************** Public Class Class1 Public Function cur1(ByVal c1 As String) As String cur1 = c1 * 43.44 MsgBox(cur1) End Function Public Function cur2(ByVal c2 As String) As String cur2 = c2 * 57.105 MsgBox(cur2) End Function

31

Public Function cur3(ByVal c3 As String) As String cur3 = c3 * 114.73 MsgBox(cur3) End Function Public Function cur4(ByVal c4 As String) As String cur4 = c4 * 12.024 MsgBox(cur4) End Function Public Function cur5(ByVal c5 As String) As String cur5 = c5 * 1.6623 MsgBox(cur5) End Function End Class CODINGS FOR PRESENTATION LAYER ****************************** Public Class Form1 Dim obj As New classLibrary1.class1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click If (ComboBox1.Text = "Usa Doller") Then Dim s = Val(TextBox1.Text) obj.cur1(s) ElseIf (ComboBox1.Text = "Eurro") Then Dim s = Val(TextBox1.Text) obj.cur2(s) ElseIf (ComboBox1.Text = "Oman Rial") Then Dim s = Val(TextBox1.Text) obj.cur3(s) ElseIf (ComboBox1.Text = "Uae Dirham") Then Dim s = Val(TextBox1.Text) obj.cur4(s) 32

ElseIf (ComboBox1.Text = "Russian Rouble") Then Dim s = Val(TextBox1.Text) obj.cur5(s) End If End Sub End Class

Result: Thus the project for converting the currency value using dot net was created and verified successfully. Ex.No: 7 DEVELOP A COMPONENT FOR CRYPTOGRAPHY USING .NET Aim:

33

To write a C# program to perform encryption and decryption of the given data. Algorithm: ALGORITHM FOR ENCRYPTION: STEP 1: Declare the class as encrypt_class. STEP 2: Start the main function. STEP 3: Declare the variable str in string data type. STEP 4: Create the object for inbuild encryption algorithm TripleDESCryptoServiceProvider. STEP 5: Create the data file using Filestream class. STEP 6: Create the object for class cryptoStream. Cryptostream is a class to invoke the Encryotor algorithm. Get the input from the user using Console.Readline(). STEP 7: Write the input data using WriteLine function. STEP 8: Create the key file using File.Create. STEP 9: convert the key file into binary form. STEP 10: Close the file. STEP 11: Print Data encrypted using console.writeLine. ALGORITHM FOR DECRYPTION : STEP 1: Declare a class as decrypt class. STEP 2: start the main function. STEP 3: Create the object for the inbuilt algorithm TripleDESCrypotserviceProvider. STEP 4: Create the file in c drive using FileStream fs =File.openRead. STEP 5: Using Binary Reader convert file as in binary form.

34

STEP 6: Read the number of bytes of key file. STEP 7: Open the data file using FileRead function. STEP 8: Cryptostream is a class to use invoke the Decrytptor. STEP 9: Create the object for CryptoStream class. STEP 10: Using StreamReader read the data file. STEP 11: Print the content of data file using Console.writeLine. STEP 12: Close the file. Program: Encryption using System; using System.IO; using System.Security.Cryptography; class encrypt_class { public static void Main() { String str; TripleDESCryptoServiceProvider cp= new TripleDESCryptoServiceProvider(); FileStream fs = File.Create("C:\\file.dat"); CryptoStream cs = new CryptoStream(fs,cp.CreateEncryptor(),CryptoStreamMode.Write); StreamWriter sw = new StreamWriter(cs); Console.WriteLine("Enter a string"); str=Console.ReadLine();

35

sw.WriteLine(str); sw.Close(); fs= File.Create("C:\\file.key"); BinaryWriter bw = new BinaryWriter(fs); bw.Write(cp.Key); bw.Write(cp.IV); bw.Close(); Console.WriteLine("Data Encrypted........"); } }

Decryption: using System; using System.IO; using System.Security.Cryptography; class decrypt_class { public static void Main() { TripleDESCryptoServiceProvider cp= new TripleDESCryptoServiceProvider(); FileStream fs = File.OpenRead("C:\\file.key"); BinaryReader br = new BinaryReader(fs); cp.Key=br.ReadBytes(24); cp.IV=br.ReadBytes(8); fs= File.OpenRead("C:\\file.dat"); CryptoStream cs = new

36

CryptoStream(fs,cp.CreateDecryptor(),CryptoStreamMode.Read); StreamReader sr = new StreamReader(cs); Console.WriteLine("Content in the file (After Decryption)"); Console.WriteLine(sr.ReadLine()); sr.Close(); } } Output: csc encrypt_class.cs encrypt_class file Enter the string Abcdefghijklmnopqrstuvwxyz Data encrypted csc decrypt_class.cs decrypt_class file Content in the file is (After decryption) Abcdefghijklmnopqrstuvwxyz.

Result: Thus the project for encryption and decryption of text using .net was created and verified successfully. Ex. No: 8 DEVELOP A COMPOENNT TO RETRIEVE MESSAGE BOX INFORMATION USING .NET

37

Aim: To create a component to retrieve message box information using .NET Algorithm: STEP 1: Open visual studio 2008. STEP 2: Chose Menu->New->Project. STEP 3: From the New Project window choose visual basic->window->windows form application. STEP 4: Give the name of the project and select the location to store the project and select ok. STEP 5: Place three textbox control on to the form design and place three buttons. Run the applications. Program: Public Class Form1 Dim a, b, c As Integer Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click c=a+b TextBox3.Text = c End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load a = InputBox("enter the first no") TextBox1.Text = a b = InputBox("enter the second no") TextBox2.Text = b MsgBox("to perform controls") End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

38

c=a-b TextBox3.Text = c End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click c=a*b TextBox3.Text = c End Sub End Class Output:

Result: Thus the project for retrieving information form message box using .net was created and verified successfully. Ex.No: 9 RETRIEVING STOCK MARKET EXCHANGE INFORMATION

39

Aim: Develop a middleware component for retrieving Stock Market Exchange information using CORBA. Algorithm: Stocket Market: STEP 1: Create the interface called StockMarket. STEP 2: Interface contains price method with one input parameters declarations. StockMarketClient: STEP 1: Import required classes. STEP 2: Define the class StockMarketClient class with required methods, STEP 3: Create the object for ORB and initiate the object with required parameters. STEP 4: Create the reference for the NameService using NamingContext reference class. STEP 5: Create the client component. StockMarketServer: STEP 1: Create the object for StockMarketImpl class. STEP 2: By using StockMarketServer object to create the reference to particular client. STEP 3: Using this reference object we can access and response the client object. Program: Stock Market.idl module SimpleStocks{ interface StockMarket { float get_price(in string symbol); }; }; 40

StockMarketClient.java import org.omg.CORBA.*; import org.omg.CosNaming.*; import SimpleStocks.*; public class StockMarketClient { public static void main(String[] args) { try { ORB orb=ORB.init(args,null); NamingContext ncRef=NamingContextHelper.narrow(orb.resolve_initial_references("NameService ")); NameComponent path[]={new NameComponent("NASDAQ","")}; StockMarket market=StockMarketHelper.narrow(ncRef.resolve(path)); System.out.println("Price of My company is"+market.get_price("My_COMPANY")); } catch(Exception e){ e.printStackTrace(); } } }

StockMarketImpl.java import org.omg.CORBA.*; 41

import SimpleStocks.*;

public class StockMarketImpl extends _StockMarketImplBase { public float get_price(String symbol) { float price=0; for(int i=0;i<symbol.length();i++) { price+=(int)symbol.charAt(i);} price/=5; return price; } public StockMarketImpl(){super();} } StockMarketServer.java: import org.omg.CORBA.*; import org.omg.CosNaming.*; import SimpleStocks.*;

public class StockMarketServer { public static void main(String[] args) { try { ORB orb=ORB.init(args,null);

42

StockMarketImpl stockMarketImpl=new StockMarketImpl(); orb.connect(stockMarketImpl); org.omg.CORBA.Object objRef=orb.resolve_initial_references("NameService"); NamingContext ncRef=NamingContextHelper.narrow(objRef); NameComponent nc=new NameComponent("NASDAQ",""); NameComponent path[]={nc}; ncRef.rebind(path,stockMarketImpl);

System.out.println("StockMarket server is ready"); Thread.currentThread().join(); } catch(Exception e){ e.printStackTrace(); } } }

Output server: G:\Programs>cd dsi G:\Programs\dsi>cd server G:\Programs\dsi\server>path=d:/jdk1.5/bin G:\Programs\dsi\server>set classpath=;.; G:\Programs\dsi\server>idlj fall stockmarket.idl G:\Programs\dsi\server>idlj fall oldImplBase stockmarket.idl G:\Programs\dsi\server>javac StockmarketImpl.java Note:.\simplestocks\_stockmarketImplBase.java uses unchecked or unsafe operations. Note: Recompile with Xlint:unchecked for details. G:\Programs\dsi\server>javac stockmarketserver.java

43

G:\Programs\dsi\server>start tnameserv ORBInitialPort 1050 G:\Programs\dsi\server>java stackmarketserver ORBInitialPort 1050 Stockmarket server is ready Output client: G:\Programs>cd dsi G:\Programs\dsi>cd client G:\Programs\dsi\ client >path=d:/jdk1.5/bin G:\Programs\dsi\ client >set classpath=;.; G:\Programs\dsi\ client >idlj fall stockmarket.idl G:\Programs\dsi\ client >javac stockmarketclient.java G:\Programs\dsi\ client >java stackmarketclient ORBInitialPort 1050 Price of my company is 216.8 G:\Programs\dsi\ client >

Result: Thus the program for retrieving store market information using CORBA was executed successfully. Ex: No: 10 DEVELOP A MIDDLEWARECOMPONENT FOR RETRIEVING WEATHER FORECAST INFORMATION USING CORBA

44

AIM: To Create a Component for retrieving stock market exchange information using CORBA. Algorithm: STEP 1: Define the IDL interface STEP 2: Implement the IDL interface using idlj compiler STEP 3: Create a Client Program STEP 4: Create a Server Program STEP 5: Start orbd. STEP 6: Start the Server. STEP 7: Start the client
Program:

Temperature.idl module simpleTemperature { interface Temperature { string get_tmp(in float a); }; }; Temperatureimpl.java import org.omg.CORBA.*; import simpleTemperature.*; public class Temperatureimpl extends _TemperatureImplBase { public String get_tmp(float a) { String c;

45

if(a<0) c="************TOO COOL***************"; else if(a<=10) c="***********COOL*********************"; else if(a<=20) c="***********MODERATE*****************"; else if(a<=30) c="***********HOT*********************"; else c="*************TOO HOT****************"; return c; } public Temperatureimpl() { super(); } } temperatureserver.java import org.omg.CORBA.*; import org.omg.CosNaming.*; import simpleTemperature.*; public class temperatureserver { public static void main(String args[]) { try { ORB orb=ORB.init(args,null); Temperatureimpl impl=new Temperatureimpl(); orb.connect(impl);

46

org.omg.CORBA.Object objref=orb.resolve_initial_references("NameService"); NamingContext ncref=NamingContextHelper.narrow(objref); NameComponent nc=new NameComponent("NASDAQ"," "); NameComponent path[]={nc}; ncref.rebind(path,impl); System.out.println("Temperature server is ready"); Thread.currentThread().join(); } catch(Exception e) { e.printStackTrace(); } } } temperatureclient.java import org.omg.CORBA.*; import org.omg.CosNaming.*; import simpleTemperature.*; public class temperatureclient { public static void main(String args[]) { try { float e=Float.parseFloat(args[2]); ORB orb=ORB.init(args,null); NamingContext ncRef=NamingContextHelper.narrow(orb.resolve_initial_references("NameService")); NameComponent path[]={new NameComponent("NASDAQ"," ")}; Temperature tempr=TemperatureHelper.narrow(ncRef.resolve(path));

47

System.out.println("\t\tweather casting"); System.out.println("\t\t........."); System.out.println("input is:"+e); System.out.println("weather is:"+tempr.get_tmp(e)); } catch(Exception e) { e.printStackTrace(); } }}

Output Server: C:\Documents and Settings\rec>g: G:\>cd programs G:\programs>cd weather forecasting G:\programs\Weather forecasting>cd server G:\programs\Weather forecasting\server>path=d:/jdk1.5/bin G:\programs\Weather forecasting\server>set classpath=;.; G:\programs\Weather forecasting\server>idlj -fall temperature.idl G:\programs\Weather forecasting\server>idlj -fall -oldImplBase temperature.idl G:\programs\Weather forecasting\server>javac Temperatureimpl.java Note: .\simpleTemperature\_TemperatureImplBase.java uses unchecked or unsafe ope rations. Note: Recompile with -Xlint:unchecked for details. G:\programs\Weather forecasting\server>javac temperatureserver.java G:\programs\Weather forecasting\server>start tnameserv -ORBInitialPort 1050 G:\programs\Weather forecasting\server>java temperatureserver -ORBInitialPort 1050 Temperature server is ready

48

Output Client: C:\Documents and Settings\rec>g: G:\>cd programs G:\programs>cd weather forecasting G:\programs\Weather forecasting>cd client G:\programs\Weather forecasting\client>path=d:/jdk1.5/bin G:\programs\Weather forecasting\client>set classpath=;.; G:\programs\Weather forecasting\client>idlj -fall temperature.idl G:\programs\Weather forecasting\client>javac temperatureclient.java G:\programs\Weather forecasting\client>java temperatureclient -ORBInitialPort 1050 8 weather casting ......... input is:8.0 weather is:***********COOL********************* G:\programs\Weather forecasting\client>

Result: Thus the program for temperature calculation using CORBA was executed successfully.

49

Vous aimerez peut-être aussi