//hello.java
import java.rmi.*;
public interface Hello extends java.rmi.Remote
String sayHello() throws RemoteException;
}
//HelloImpl.java
import java.rmi.Naming;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
public class HelloImpl extends UnicastRemoteObject implements Hello
{
public HelloImpl() throws RemoteException {}
public String sayHello() { return "Hello world!"; }
public static void main(String args[])
{
try
{
HelloImpl obj = new HelloImpl();
// Bind this object instance to the name "HelloServer"
Naming.rebind("HelloServer", obj);
}
catch (Exception e)
{
System.out.println("HelloImpl err: " + e.getMessage());
e.printStackTrace();
}
}
}
//HelloClient.java
import java.rmi.RMISecurityManager;
import java.rmi.Naming;
import java.rmi.RemoteException;
public class HelloClient
{
public static void main(String arg[])
{
String message = "blank";
// I download server's stubs ==> must set a SecurityManager
System.setSecurityManager(new RMISecurityManager());
try
{
Hello obj = (Hello) Naming.lookup( "//" +
"lysander.cs.ucsb.edu" +
"/HelloServer"); //objectname in registry
System.out.println(obj.sayHello());
}
catch (Exception e)
{
System.out.println("HelloClient exception: " + e.getMessage());
e.printStackTrace();
}
}
}
software girl
0
Newbie Poster
Recommended Answers
Jump to PostWhat exactly are you saying here? Sounds like "I don't like any of the tutorials on the web, so write one just for me"?
Anyway - you don't need to worry about make files for this simple example. Just compile all your classes with javac.exe, run the server and run …
Jump to PostI don't want to upset you, but RMI is an advanced Java topic, and if you are unsure about how to compile a java file then you are not ready for RMI yet. I recommend that you set RMI aside for now, and work the basics first. Then come back …
Jump to Postand you're wrong. You have to use rmic to create the stub classes which then are compiled together with the rest of the code using javac.
All 12 Replies
software girl
0
Newbie Poster
software girl
0
Newbie Poster
JamesCherrill
4,733
Most Valuable Poster
Team Colleague
Featured Poster
software girl
0
Newbie Poster
JamesCherrill
4,733
Most Valuable Poster
Team Colleague
Featured Poster
software girl
0
Newbie Poster
edensigauke
-8
Light Poster
jwenting
1,889
duckman
Team Colleague
stultuske
1,116
Posting Maven
Featured Poster
JamesCherrill
4,733
Most Valuable Poster
Team Colleague
Featured Poster
software girl
0
Newbie Poster
jwenting
1,889
duckman
Team Colleague
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.