在RMI程序中怎样设置java.rmi.server.codebase的相关推荐
1个回答
2015-01-23
展开全部
你想实现几个接口都是可以的,只要符合远程接口的规范
类似下面的代码这样写啊
远程接口实例
import java.rmi.Remote;
import java.rmi.RemoteException;
public interface Hello extends Remote
{
String sayHello() throws RemoteException;
}
它定义了一个方法,sayHello,实现向调用者返回一个字符串
Server类
import java.rmi.registry.Resistry;
import java.rmi.registry.LocateRegistry;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
public class Server implements Hello
{
public Server(){}
public String sayHello()
{
return “Hello,World!”;
}
public static void main(String args[])
{
Try{
Server obj=new Server ();
Hello stub=(Hello)UnicastRemoteObject.explortObject(obj,0);
//Bind the remote object’ s stub in the registry
Registry registry=LocateRegistry.getRegistry();
Registry.bind(“Hello”,stub);
System.err.println(“Server ready”);
}catch(Exception e)
{
System.err.println(“Server exception:”+e.toString());
e.printStackTrace();
}
}
}
类似下面的代码这样写啊
远程接口实例
import java.rmi.Remote;
import java.rmi.RemoteException;
public interface Hello extends Remote
{
String sayHello() throws RemoteException;
}
它定义了一个方法,sayHello,实现向调用者返回一个字符串
Server类
import java.rmi.registry.Resistry;
import java.rmi.registry.LocateRegistry;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
public class Server implements Hello
{
public Server(){}
public String sayHello()
{
return “Hello,World!”;
}
public static void main(String args[])
{
Try{
Server obj=new Server ();
Hello stub=(Hello)UnicastRemoteObject.explortObject(obj,0);
//Bind the remote object’ s stub in the registry
Registry registry=LocateRegistry.getRegistry();
Registry.bind(“Hello”,stub);
System.err.println(“Server ready”);
}catch(Exception e)
{
System.err.println(“Server exception:”+e.toString());
e.printStackTrace();
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询