Subject : JAVA RMI Test ù¹ø° ¿¹Á¦

Solution Description:
=====================

. ±¸ÇöÄÚµå »ý¼º

www% mkdir $HOME/temp/rmi/src/examples/hello

 - remote interface Á¤ÀÇ

www% vi Hello.java

package examples.hello;

public interface Hello extends java.rmi.Remote {
    String sayHello() throws java.rmi.RemoteException;
}


 - remote interface¸¦ ±¸ÇöÇÏ´Â java remote object(server) Á¤ÀÇ

www% vi HelloImpl.java

package examples.hello;

import java.rmi.*;
import java.rmi.server.UnicastRemoteObject;

public class HelloImpl
	extends UnicastRemoteObject
	implements Hello
{   
    private String name;
 
    public HelloImpl(String s) throws java.rmi.RemoteException {
	super();
	name = s;
    }
    
    public String sayHello() throws RemoteException {
	return  "Hello World!";
    }

    public static void main(String args[]) 
    {
	// Create and install the security manager
	System.setSecurityManager(new RMISecurityManager());

	try {
	    HelloImpl obj = new HelloImpl("HelloServer");
	    Naming.rebind("HelloServer", obj);
	    System.out.println("HelloImpl created and bound in the registry to the name HelloServer");

	} catch (Exception e) {
	    System.out.println("HelloImpl.main: an exception occurred:");
	    e.printStackTrace();
	}
    }
}


 - serverÀÇ method¸¦ ºÎ¸£´Â(invoke) applet »ý¼º

www% vi HelloApplet.java

package examples.hello;

import java.awt.*;
import java.rmi.*;

public class HelloApplet extends java.applet.Applet {

    String message = "";

    public void init() {

    try {
	Hello obj = (Hello)
	    Naming.lookup("//" + getCodeBase().getHost() + "/HelloServer");
	message = obj.sayHello();

	} catch (Exception e) {
	    System.out.println("HelloApplet: an exception occurred:");
	    e.printStackTrace();
	}
    }
   
    public void paint(Graphics g) {
	g.drawString(message, 25, 50);
    }

}


. Compile & Generate Stubs and Skeletons 

www% cd $HOME/temp/rmi/src/examples/hello

www% javac -d $HOME/public_html/codebase Hello.java HelloImpl.java HelloApplet.java

www% cd $HOME/public_html/codebase

www% rmic -d $HOME/public_html/codebase examples.hello.HelloImpl

www% cd ./examples/hello

 - html code »ý¼º

www% vi index.html


Hello World

Hello World

The message from the HelloServer is:

www% ls Hello.class HelloImpl.class index.html HelloApplet.class HelloImpl_Skel.class HelloApplet.html HelloImpl_Stub.class - $HOME/public_html/codebase¸¦ CLASSPATH ¼³Á¤ . ½ÇÇà www% rmiregistry & /* rmi bootstrap registry start, default port 1099 */ www% cd $HOME/public_html/codebase www% java -Djava.rmi.server.codebase=http://www.svc.hei.co.kr/~java/codebase/ examples.hello.HelloImpl & /* Server start, "HelloImpl created and bound in the registry to the name server HelloServer" message Ãâ·Â, ok */ - ´ç½ÅÀÇ ½Ã½ºÅÛ(client)¿¡¼­ www% appletviewer http://www.svc.hei.co.kr/~java/codebase/examples/hello/index.html ---------------------------------------------------------------------------- Revision History ÀÛ¼ºÀÏÀÚ : 97.07.10 ÀÛ¼ºÀÚ : À̹ÎÈ£ ¼öÁ¤ÀÏÀÚ : ¼öÁ¤ÀÚ :