±Û¾´ÀÌ :±Ç¿µÁØ 1999³â 3¿ù 04ÀÏ 18:06:55
¾È³çÇϼ¼¿ä. ±Ç¿µÁØÀ̶ó°í ÇÕ´Ï´Ù.
rmi¸¦ °øºÎÇÏ°í ÀÖ½À´Ï´Ù.
rmi Äݹ鿡¼ javac -d . RMIChatServer.java RMIChatServerImpl.java
Çϸé, 4°³ÀÇ ¿¡·¯°¡ ¶³¾îÁý´Ï´Ù.
¿¡·¯³»¿ë ->
1¹ø° ¿¡·¯
A default construcotr cannot be created for this class because the constructor of its superclass throws the exception java.rmi.RemoteException.
Define the constructor for this class explicitly.
2,3 ¹ø°¿¡·¯
class rmichat.public not found
4¹ø° ¿¡·¯
only constructors can invoke constructors;
super()
ÀÌ·¸°Ô ¿¡·¯°¡ ³³´Ï´Ù.
±×¸®°í, rmi P/G¿¡¼´Â javac -d . RMIChat.....
ÀÌ·±½ÄÀ¸·Î ÇØÁִµ¥, javac -d . ´Â ¿Ö ÀÌ·¸°Ô Çϴ°ÅÁÒ..
±×¸®°í, DOS Command »ó¿¡¼ javac -d . 2°³ÀÇ java file
ÀÌ·¸°Ô ÇØÁִµ¥, kawa¿¡¼´Â ¾î¶»°Ô ÇϸéµÇÁÒ.(ÀÚ¼¼È÷)
javac -d . RMIChatClient.java RMIChatClientApplet.java ÇÏ¸é ¿¡·¯°¡ ¾ø½À´Ï´Ù.
½î¾²¸¦ ÷ºÎÇÏ¿© µå¸³´Ï´Ù.
* RMIChatServer.java
package rmichat;
import java.rmi.*;
public interface RMIChatServer extends Remote {
public void register(RMIChatClient client) throws RemoteException;
public void broadcast(String msg) throws RemoteException;
public void unregister(RMIChatClient client) throws RemoteException;
}
* RMIChatServerImpl.java
package rmichat;
import java.rmi.server.*;
import java.rmi.*;
import java.util.*;
public class RMIChatServerImpl extends UnicastRemoteObject implements RMIChatServer
{
Vector clientList;
pulbic RMIChatServerImpl() throws RemoteException {
super();
clientList=new Vector(5, 5);
}
public synchronized void register(RMIChatClient client) throws RemoteException
{
clientList.addElement(client);
}
public void broadcast(String msg) throws RemoteException {
synchronized(clientList) {
Enumeration e = clientList.elements();
while(e.hasMoreElements()) {
RMIChatClient c = (RMIChatClient)e.nextElement();
c.setMessage(msg);
}
}
}
public synchronized void unregister(RMIChatClient client) throws RemoteException
{
clientList.removeElement(client);
}
public static void main(String args[]) {
System.setSecurityManager(new RMISecurityManager());
try {
RMIChatServerImpl c = new RMIChatServerImpl();
Naming.rebind("rmi://localhost/chat", c);
System.out.println("RMI Chat Server is ready.");
} catch(Exception ex) {
System.out.println(ex);
}
}
* RMIChatClient.java
package rmichat;
import java.rmi.*;
public interface RMIChatClient extends Remote {
public void setMessage(String msg) throws RemoteException;
}
* RMIChatClinetApplet.java
package rmichat;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.rmi.*;
import java.rmi.server.*;
public class RMIChatClientApplet extends Applet implements RMIChatClient, ActionListener {
TextArea display;
TextField input;
RMIChatServer server;
public void init() {
setLayout(new BorderLayout());
add("Center", display = new TextArea());
display.setEditable(false);
add("South", input = new TextField());
input.addActionListener(this);
try {
UnicastRemoteObject.exportObject(this);
System.out.println(getCodeBase().getHost() + "/chat");
server.register(this);
} catch (Exception ex) {
display.append(ex.toString());
}
}
public synchronized void setMessage(String msg) {
try {
display.append(msg + "\n");
} catch(Exception e) {
display.append(e.toString());
}
}
public void actionPerformed(ActionEvent e) {
Component c = (Component) e.getSource();
if(c == input) {
try {
server.broadcast(input.getText());
input.setText("");
} catch (Exception ex) {
display.append(ex.toString());
}
}
}
public void destroy() {
try {
server.unregister(this);
} catch(Exception ex) { }
}
}
* javaplugN.html
<EMBED type="application/x-java-applet;version=1.1"
code="RMIChatClientApplet.class"
pluginspage="http://java.sun.com/products/activator/ea3/plugin-install.html"
width=400 height=300>
</EMBDE>
}