It's not a secret anymore!*
The moose likes Distributed Java and the fly likes in running client for rmi-> unknown host exception:host exception need a solution Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Distributed Java
Bookmark "in running client for rmi-> unknown host exception:host exception need a solution" Watch "in running client for rmi-> unknown host exception:host exception need a solution" New topic
Author

in running client for rmi-> unknown host exception:host exception need a solution

zshell agarwal
Greenhorn

Joined: Apr 01, 2012
Posts: 1


CLIENT PROGRAM:

import java.io.*;

import java.rmi.*;

public class client

{

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

{

try

{

String s="rmi://"+args[0]+"/abc";

serverint f=(serverint)Naming.lookup(s);

DataInputStream m=new DataInputStream(System.in);

int n1=Integer.parseInt(m.readLine());

System.out.println("the factorial is"+f.fact(n1));

}

catch(Exception e)

{

System.out.println(e);

}

}

}









INTERFACE PROGRAM:

import java.rmi.*;

public interface serverint extends Remote

{

int fact(int n)throws Exception;

}



IMPLEMENTATION PROGRAM:

import java.rmi.*;

import java.rmi.server.*;

public class serverimpl extends UnicastRemoteObject implements serverint

{

public serverimpl()throws Exception

{

}

public int fact(int n)

{

int i,c=1;

for(i=1;i<=n;i++)

{

c=i*c;

}

return c;

}

}



SERVER PROGRAM:

import java.net.*;

import java.rmi.*;

public class server

{

public static void main(String args[])

{

try

{

serverimpl m=new serverimpl();

Naming.rebind("abc",m);

}

catch(Exception e)

{

System.out.println("Exception"+e);

}

}

}









OUTPUT:



SERVER WINDOW:

C:\factorial2>javac server.java


C:\factorial2>start java server



CLIENT WINDOW:

C:\factorial2>javac client.java

Note: client.java uses or overrides a deprecated API.

Note: Recompile with -Xlint:deprecation for details.

C:\factorial>java client localhost










ERROR:
java.rmi.UnknownHostException: Unknown host: hostname; nested exception is:
java.net.UnknownHostException: hostname
Ram Narayan.M
Ranch Hand

Joined: Jul 11, 2010
Posts: 247

Please use CodeTags to highlight the code...

Seeing the exception, you have given the hostname as "hostname" itself...

Give the correct input and try

SCJP 6 [SCJP - Old is Gold]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: in running client for rmi-> unknown host exception:host exception need a solution
 
Similar Threads
Help needed in RMI
App won't run when client is on a different machine than server - $donation
Rmi with SSL problem
RMI - Remote Method Invocation
Learning RMI for SCJD