| 導購 | 订阅 | 在线投稿
分享
 
 
 

Java RMI編程

來源:互聯網網民  2008-05-31 12:10:42  評論

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

}

 
特别声明:以上内容(如有图片或视频亦包括在内)为网络用户发布,本站仅提供信息存储服务。
 
<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- 王朝網路 版權所有