Hello everyone,
I am beginner in java programming,when i try to run the program on the server side it is running fine but on the client side when i execute the code i get the error message java.rmi.unknownhostexception :unknown host: pc error. Program contains 4 files. I will post the code below.
ForExServerIntf.java
import java.rmi.*; public interface ForExServerIntf extends Remote { float currency(float f1) throws RemoteException; }
ForExServerImpl.java
import java.rmi.*; import java.rmi.server.*; public class ForExServerImpl extends UnicastRemoteObject implements ForExServerIntf { public ForExServerImpl() throws RemoteException{} public float currency(float f1) throws RemoteException { return f1/49; } }
ForExServer.java
import java.rmi.*; import java.net.*; public class ForExServer { public static void main(String args[]) { try { ForExServerImpl ForExImpl=new ForExServerImpl(); Naming.rebind("ForExServer",ForExImpl); System.out.println("Server is running"); } catch(Exception e) { System.out.println(e); } } }
ForExClient.java
import java.io.*; import java.rmi.*; public class ForExClient { public static void main(String args[]) { try { String ForExURL="rmi://"+args[0]+"/ForExServer"; ForExServerIntf ForExServerIntf=(ForExServerIntf)Naming.lookup(ForExURL); System.out.println("Enter value in rupees:"+args[1]); float f1=Float.valueOf(args[1]).floatValue(); double d=ForExServerIntf.currency(f1); System.out.println("Converted value from rupees to dollar:"+d); double r=((int)((d*100.0)+0.5))/100.0; System.out.println("\nRounded value is:"+r); } catch(Exception e) { e.printStackTrace(); System.out.println("Error"); } } }
Attachment of client side is given below
rmiregistry1.JPG
Please can anyone help me to solve the error.