• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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
 
Ranch Hand
Posts: 247
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please use CodeTags to highlight the code...

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

Give the correct input and try
 
reply
    Bookmark Topic Watch Topic
  • New Topic