WEB开发网
开发学院WEB开发Jsp Java RMI编程 阅读

Java RMI编程

 2008-01-05 19:07:49 来源:WEB开发网   
核心提示:<b>Step 1: Implementstheinterface of Remote Server as SimpleCounterServer.java</b>public interface SimpleCounterServer extends java.rmi.Remote{publi

<b>Step 1: Implements the interface of Remote Server as SimpleCounterServer.java</b>

  public interface SimpleCounterServer extends java.rmi.Remote
{
  public int getCount() throws java.rmi.RemoteException;
  
}
Compile it with javac SimpleCounterServer.java

<b>Step 2:   PRodUCe the implement file SimpleCounterServerImpl.java as</b>
import java.rmi.*;
import java.rmi.server.UnicastRemoteObject;
//
//
// SimpleCounterServerImpl
//
//
public class SimpleCounterServerImpl
extends UnicastRemoteObject
implements SimpleCounterServer
{
  private int iCount;
  public SimpleCounterServerImpl() throws java.rmi.RemoteException
  {
    iCount = 0;
  }
  public int getCount() throws RemoteException
  {
    return ++iCount;
  }

  public static void main(String args[])
  {
    System.setSecurityManager(new RMISecurityManager());
    try
    {
      SimpleCounterServerImpl server = new SimpleCounterServerImpl();
      System.out.println("SimpleCounterServer created");
      Naming.rebind("SimpleCounterServer",server);
      System.out.println("SimpleCounterServer registered");
    }
    catch(RemoteException x)
    {
      x.printStackTrace();
    }    

Tags:Java RMI 编程

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接