Java RMI编程

王朝java/jsp·作者佚名  2008-05-31
窄屏简体版  字體: |||超大  

<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();

}

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航