sivaramaiah  
 
  Record 4 04/18/2024 4:18pm (UTC)
   
 
 
Record 4:Stockmarket:
Create a remote stock server that accepts the company name and gives the share value. Stock client that retrieves the company share value and displays by giving the company name.
-----------------------------------------------------------------------------------------

Program 1: Interface program                          ShareVal.java
import java.rmi.*;

public interface ShareVal extends Remote
{
    public float getShareValue(String Company) throws RemoteException;
Program 2: Implementation program                            ShareValImp.java
import java.rmi.*;
import java.rmi.server.*;
import java.io.*;

public class ShareValImp extends UnicastRemoteObject implements ShareVal
{

    public ShareValImp() throws RemoteException
    {
        super();
    }
    
    public float getShareValue(String Company) throws RemoteException
    {

        byte buffer[] = new byte[2056];
        try
        {
            FileInputStream fis = new FileInputStream("shares.txt");
            int bytes = fis.read(buffer,0,2056);
            try
            {
                String str = new String(buffer,0,bytes,"Default");
                String[] shares = str.split("~");

                for(int i=0;i<shares.length;i++)
                {
                    if(shares[i].trim().compareTo(Company)==0)
                    return(Float.parseFloat(shares[i+1].trim()));    
                }
                
            }
            catch(Exception e)
            { System.out.println("Error, maybe string error :"+e);
            }
        }
        catch(Exception e)
        { System.out.println("Error at ShareValImp : "+e);
        }
    return 0;
    }
}
-------------------------------------------------------------
Program 3: Server program                                               ShareValServer.java
import java.rmi.*;
import java.rmi.server.*;

public class ShareValServer
{
    public static void main(String[] args)
    {
        try
        {
        System.out.print("Constructing Server Implementation...");
        ShareValImp SV1 = new ShareValImp();

        Naming.rebind("Shares",SV1);

        System.out.print("Done!nWaiting for Invocations from client...n");
        }
        catch(Exception e)
        { System.out.print("Error at ShareValServer : "+e);
        }
    }
}
Program 4: Client program                                                ShareValClient.java
import java.rmi.*;
import java.rmi.server.*;
import java.io.*;

public class ShareValClient
{
    public static void main(String[] args)
    {
    
        try
        {
        System.out.print("Enter Company Name : ");
        DataInputStream dis = new DataInputStream(System.in);
        String coy = dis.readLine();
        System.out.print("Naming.lookup for Bindings...");
        ShareVal SVal = (ShareVal) Naming.lookup("Shares");

        System.out.print("Done!n");

        System.out.println("Company : "+coy+"'s Share value = "+SVal.getShareValue(coy));
        
        }
        catch(Exception e)
        { System.out.print("Error at ShareValClient : "+e);
        }
    }
}
------------------------------------------------------------
Program 5: text file             shares.txt
------------------------------------------------------------
HCL~125.50~
HP~124.50~
WIPRO~100.25~
SATYAM~99.75~
MICROSOFT~150.50~
IBM~145.75~
SUNMICRO~200.75~
AMD~175.90~
INTEL~180.95
------------------------------------------------------------
Program 6: Show Bindings                                                  showBingings.java
import java.rmi.*;
import java.rmi.server.*;
 
public class showBindings
{
            public static void main(String[] args)
            {
                        try
                        {
                                    String[] bindings = Naming.list("");
                                    for(int i=0;i<bindings.length;i++)
                                    System.out.println("Binding ["+(i+1)+"] => "+bindings[i]);
                        }
                        catch(Exception e)
                        { System.out.println("Error in showBindings : "+e.toString());     }
                       
            }
}
Program 7: clinet.policy                                    clinet.policy
grant
{
            permission java.net.SocketPermission
            "*:1024-65335","connect";
};
How to run the program
1. compile all java files
 
            javac *.java
 
2. use RMICompiler to create stubs & skeletons of Implementations
           
            rmic ShareValImp
 
3. run rmiregistry
           
            start rmiregistry
 
4. create policy file with following contents
 
            client.policy
            ~~~~~~~~~~~~~
           
            grant
            {
                        permission java.net.SocketPermission
                        "*:1024-65335","connect";
            };
 
5. run server
 
            java ShareValServer
 
6. run client with policy created in step 4.
 
            java -Djava.security.policy=client.policy ShareValClient
 
 

 
  Menu Items
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

  add
HOT TOPICS
MCA PROJECT DETAILS ------------------------------------- Jntu all Lab manuals ------------------------------------- Jntu Syllabus Books ------------------------------------- Paper presentations ------------------------------------- Seminars ------------------------------------- Campus Papers ------------------------------------- Competetive Exams GATE ------------------------------------- GRE ------------------------------------- TOEFL ------------------------------------- IELTS ------------------------------------- CAT ------------------------------------- GMAT ------------------------------------- Templates ------------------------------------- Students Resume Preparation tips ------------------------------------- Job zone(Interview questions) ------------------------------------- Google Adsence html code ------------------------------------- Web sites --------x--------------x-----------
  Advertisement

 


-----------------------------
  Offline Messages
  Adds
  Visitors Information
Today, there have been 119561 visitors (281024 hits) on this page!
-------------------------------------------------- This website was created for free with Own-Free-Website.com. Would you also like to have your own website?
Sign up for free