public interface Hello extends java.rmi.Remote {
public String sayHello(String name) throws java.rmi.RemoteException;
}
public String sayHello(String name) throws java.rmi.RemoteException;
}
//HelloClient.java, 실행시 이름을 인자로...
import java.rmi.Naming;
public class HelloClient {
public static void main(String[] args) {
try {
Object obj = Naming.lookup("rmi://loclahost:1099/HelloRemote");
Hello remoteObj = (Hello)obj;
String msg = remoteObj.sayHello(args[0]);
System.out.println(msg);
}
catch(java.rmi.RemoteException e) {
System.out.println("Something has gone wrong during remote method call..."+e);
}
catch(java.rmi.NotBoundException e) {
System.out.println("Could't bound..."+e);
}
catch(java.net.MalformedURLException e) {
System.out.println("Check url stirng..."+e);
}
}
}
import java.rmi.Naming;
public class HelloClient {
public static void main(String[] args) {
try {
Object obj = Naming.lookup("rmi://loclahost:1099/HelloRemote");
Hello remoteObj = (Hello)obj;
String msg = remoteObj.sayHello(args[0]);
System.out.println(msg);
}
catch(java.rmi.RemoteException e) {
System.out.println("Something has gone wrong during remote method call..."+e);
}
catch(java.rmi.NotBoundException e) {
System.out.println("Could't bound..."+e);
}
catch(java.net.MalformedURLException e) {
System.out.println("Check url stirng..."+e);
}
}
}
import java.rmi.server.*;
import java.rmi.*;
import java.rmi.*;
public class HelloImpl extends UnicastRemoteObject implements Hello
{
//public HelloImpl() throws RemoteException {
// super();
//}
//public HelloImpl() throws RemoteException {
// super();
//}
//원격 메소드 구현
public String sayHello(String name) {
return "Hello World ... " + name + "!";
}
}
public String sayHello(String name) {
return "Hello World ... " + name + "!";
}
}
//HelloServer.java
public class HelloServer {
public static void main(String[] args) {
try {
HelloImpl remoteObj = new HelloImpl();
java.rmi.Naming.rebind("rmi://localhost:1099/HelloRemote", remoteObj);
System.out.println("Hello Remote Object bound to the registry and ready to service incoming client calls...");
}
catch(java.rmi.RemoteException e) {
System.err.println("Exception occurred during processing incoming method call"+e);
}
catch(java.net.MalformedURLException e) {
System.err.println("Check the url String..."+e);
}
}
}
public class HelloServer {
public static void main(String[] args) {
try {
HelloImpl remoteObj = new HelloImpl();
java.rmi.Naming.rebind("rmi://localhost:1099/HelloRemote", remoteObj);
System.out.println("Hello Remote Object bound to the registry and ready to service incoming client calls...");
}
catch(java.rmi.RemoteException e) {
System.err.println("Exception occurred during processing incoming method call"+e);
}
catch(java.net.MalformedURLException e) {
System.err.println("Check the url String..."+e);
}
}
}
댓글 없음:
댓글 쓰기