Browser¿¡¼­ÀÇ RMI Applet


[ ´ÙÀ½ ±Ûµé ] [ À̾ ±Û¿Ã¸®±â(´äÇϱâ) ] [ ÀÚ¹Ù ¹¯°í ´äÇϱâ ]

±Û¾´ÀÌ :ÀÌ¿ø¿µ 1998³â 12¿ù 02ÀÏ 10:42:20

In Reply to: rmi»ç¿ëÇؼ­ 3-tier·Î ÇÏ´Â ¾ÖÇø´¿¡ ¹®Á¦°¡..- -; posted by ±èÁ¤Çý on 1998³â 12¿ù 01ÀÏ 16:09:06:

´©°¡ ±×·± ¸»À» ÇÒ±î¿ä.. Àß µÇ´Âµ¥...
3-tier·Î RMI¸¦ »ç¿ëÇÏ´Â AppletÀ̶ó ÇÔÀº
Applet¿¡¼­ ¿ø°ÝÁö ¸Ó½ÅÀÇ RMI Server Object¸¦
bindingÇÏ°í, RMI Server Object´Â JDBC¸¦ ÀÌ¿ëÇØ
DB¸¦ ¹°°í ÀÖ´Â °æ¿ì¸¦ ¸»¾¸ÇϽô °Í ¸ÂÁÒ?
JDBC¿¬°áÀº ÀÌ °÷ [ÀÚ¹Ù¹¯°í´äÇϱâ]¿¡ ¸¹Àº ÇØ°áÃ¥ÀÌ
ÀÖ°í, Applet°ú RMI Server°¡ ¹®Á¦Àΰ¡¿ä?


1. [°æ¿ì1] JDK 1.1ÀÇ RMI bug
RMI Server°¡ ÀÚ½ÅÀÇ À̸§À» Registry¿¡ µî·ÏÇÒ¶§
rmi://xxx.domain.co.kr:1234/ServerName µî°ú °°Àº
¹æ¹ýÀ¸·Î full dns nameÀ¸·Î µî·ÏÇϱ⠶§¹®¿¡
¹ß»ýÇÕ´Ï´Ù.
RMI Server°¡ ÀÖ´Â ¸Ó½ÅÀÌ DNS¿¡ µî·ÏµÇ¾î ÀÖÁö ¾ÊÀ¸¸é
±âº»ÀûÀ¸·Î ¾ÈµÇ´Â °ÅÁö¿ä...
±×·¡¼­ RMI Server°¡ Registry¿¡ µî·ÏÇÒ ¶§
dns nameÀÌ ¾Æ´Ï¶ó IP Address·Î µî·ÏÇϵµ·Ï ¹Ù²Ù¾î
ÁÖ¾î¾ß ÇÕ´Ï´Ù.
java.rmi.server.hostname ¶ó´Â property¿¡
¸Ó½Å IP address¸¦ settingÇØ ÁÖ¸é µÇÁö¿ä.


RMIÀÇ ÀÌ ¹®Á¦´Â ¾Æ·¡¿Í °°Àº ¹æ¹ýÀ¸·Î ÇØ°áµË´Ï´Ù.
applet¿¡¼± Ưº°È÷ ÇÒ °ÍÀÌ ¾ø±¸¿ä..
RMI ServerºÎºÐÀ» ´ÙÀ½ ó·³ ÇØ º¸¼¼¿ä.


import java.net.*;
import java.rmi.*;
import java.rmi.server.*;
import java.rmi.registry.LocateRegistry;
import java.util.*;


public class Server
{
static final String SERVER_NAME = "RemoteServer";
static final int SERVER_PORT = 7942;
public static void main(String argv[]) throws ClassNotFoundException
{
try{
InetAddress address = InetAddress.getLocalHost();
String thisHost = address.getHostAddress();
Properties properties = System.getProperties();
properties.put("java.rmi.server.hostname", thisHost);
System.setProperties(properties);
System.setSecurityManager (new RMISecurityManager());
LocateRegistry.createRegistry(SERVER_PORT);
YourOwnRemoteServer remoteServer = new YourOwnRemoteServer();
Naming.rebind("//:" + SERVER_PORT + "/" + SERVER_NAME , remoteServer);
}
catch (Exception e){
e.printStackTrace();
}
}
}



2. [°æ¿ì2] CodingÀ» Á¦´ë·Î ÇÏÁö ¾ÊÀº °æ¿ì
¸ÕÀú JDKÀÇ ¿¹Á¦Áß RMI Hello¸¦ ¾à°£ ¼öÁ¤ÇÑ ¾Æ·¡ÀÇ ³»¿ëÀ» °¡Áö°í ¸ÕÀú testÇØ
º¸½Ç °ÍÀ» ±ÇÇÕ´Ï´Ù.



[HelloInterface.java]
import java.rmi.*;
public interface HelloInterface extends java.rmi.Remote {
Object sayHello() throws java.rmi.RemoteException;
}


[HelloServer.java]
import java.net.*;
import java.util.*;
import java.rmi.*;
import java.rmi.server.UnicastRemoteObject;
import java.rmi.registry.LocateRegistry;


public class HelloServer extends UnicastRemoteObject implements HelloInterface
{
private String name;
public HelloServer(String s) throws java.rmi.RemoteException {
super();
name = s;
}
public Object sayHello() throws RemoteException {
String string = new String("Hey! How are you? Im's Remote Server." );
return (Object)string;
}
public static void main(String args[]) {
int PORT = 7943;
try {
InetAddress address = InetAddress.getLocalHost();
String thisHost = address.getHostAddress();
Properties properties = System.getProperties();
properties.put("java.rmi.server.hostname", thisHost);
System.setProperties(properties);
System.setSecurityManager (new RMISecurityManager());
LocateRegistry.createRegistry( PORT );
HelloServer server = new HelloServer("HelloServer");
Naming.rebind("//:" + PORT + "/HelloServer", server);
}
catch (Exception e) {
System.out.println("HelloServer.main: an exception occurred:");
e.printStackTrace();
}
}
}



[HelloApplet.java]
import java.awt.*;
import java.rmi.*;
public class HelloApplet extends java.applet.Applet {
private final int PORT = 7943;
String message ;
TextArea t;
public void init() {
t = new TextArea();
setLayout(new BorderLayout());
add("Center", t);
try {
HelloInterface server = (HelloInterface) Naming.lookup("//" +
getCodeBase().getHost() + ":" + PORT +
"/HelloServer");
String message = (String)server.sayHello();
t.append(message + "\n");
} catch (Exception e) {
System.out.println("HelloApplet: an exception occurred:");
e.printStackTrace();
}
}
}



[HelloApplet.html]
<HTML>
<title>Hello World</title>
<center> <h1>Hello World</h1> </center>
The message from the HelloServer is:
<p>
<applet code="HelloApplet.class" width=500 height=120>
</applet>
</HTML>



[±¸µ¿ ¹æ¹ý]
1. À§ÀÇ ¼¼°³ÀÇ .javaÆÄÀÏ°ú .htmlÆÄÀÏÀ» À¥¼­¹öÀÇ Àû´çÇÑ ¹®¼­ µð·ºÅ丮¿¡
copyÇϼ¼¿ä.
2. javac *.java
3. rmic HelloServer
4. java HelloServer
(´ë±â»óÅ·ΠµÇ¸é RMI¼­¹ö°¡ Á¦´ë·Î ¶á °ÍÀÓ)
ȤÀº java HelloServer &
5. Netscape·Î À¥¼­¹öÀÇ HelloApplet.htmlÀ» Àо´Ù.


ºÐ¸íÈ÷ µÉ °Ì´Ï´Ù.
Çà¿îÀ»....
================================================
236-1, Hyosung-2dong, Kyeyang-gu, Inchun,
407-042, KOREA
Phone:(82-32)540-5243, Fax:(82-32)540-5402
PCS:019-310-7324
http://math.kyungpook.ac.kr/~leewy/
================================================



´ÙÀ½ ±Ûµé:



À̾ ±Û¿Ã¸®±â(´äÇϱâ)

À̸§:
E-Mail:
Á¦¸ñ:
³»¿ë:
HTML ÅÂ±× Æ÷ÇÔ ¿©ºÎ: HTML ¹®¼­ÀÏ °æ¿ì üũ
°ü·Ã URL(¼±ÅÃ):
URL Á¦¸ñ(¼±ÅÃ):
°ü·Ã À̹ÌÁö URL:


[ ´ÙÀ½ ±Ûµé ] [ À̾ ±Û¿Ã¸®±â(´äÇϱâ) ] [ ÀÚ¹Ù ¹¯°í ´äÇϱâ ]