67,515
社区成员
发帖
与我相关
我的任务
分享
import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
public class RMIServer {
public static void startServer() throws RemoteException, MalformedURLException {
// 启动rmi注册服务,指定端口1099也可以直接命令行启动一个注册服务生成stub
LocateRegistry.createRegistry(1099);
// 创建远程对象一个或者多个实例
FingerGatherManage fingerGatherManage = new FingerGatherManageImpl();
// 把对象注册到另一台启动了rmi注册服务的机器
Naming.rebind("rmi:/192.168.10.28:1099/FingerGatherManage", fingerGatherManage);
System.out.println("rmi服务器启动了");
}
}
public class RMIConnection {
public static List<List<Object>> validateUserNameAndPassword(String ip, int portNum, String userName, String password) throws MalformedURLException, RemoteException, NotBoundException {
FingerGatherManage fingerGatherManage = (FingerGatherManage) Naming
.lookup("rmi:/" + ip + ":" + portNum + "/FingerGatherManage");
List<List<Object>> result = fingerGatherManage.validateUserNameAndPassword(userName, password);
return result;
}
}