[英]running java rmi server
I am creating a project with RMI technology and it's running as I want but now I want to upload my RMI class to the server, how and what should I do that ? 我正在使用RMI技术创建一个项目,并且该项目可以按我的意愿运行,但是现在我想将RMI类上传到服务器,该怎么做以及应该怎么做?
I tried to do this: 我试图这样做:
public static void main (String [] arg) {
try {
LocateRegistry.createRegistry(30);
Registry reg = LocateRegistry.getRegistry("127.0.0.1",30);
ImbCal c = new ImbCal();
reg.rebind("MSA", c);
reg.rebind("Work", c);
System.out.println("Server is ready ....");
System.in.read();
}catch(Exception ex){
ex.printStackTrace();
System.out.print(ex.getMessage());
}
}
I know that should: 我知道应该:
I have already created an interface and a client class and tested my project locally and it works perfectly. 我已经创建了一个接口和一个客户端类,并在本地测试了我的项目,并且效果很好。
I tried a lot until i solved it , I just need to create registry in server class while in client class i should get registry by the address of server class 在尝试解决之前,我做了很多尝试,我只需要在服务器类中创建注册表,而在客户端类中,我应该通过服务器类的地址获取注册表
Server class : 服务器类:
try {
/*here create the registry*/
Registry reg = LocateRegistry.createRegistry(30);
ImbCal c = new ImbCal();
reg.rebind("MSA", c);
reg.rebind("Work", c);
System.out.println("Server is ready ....");
System.in.read();
}catch(Exception ex){
ex.printStackTrace();
System.out.print(ex.getMessage());
}
Client Class : 客户类别:
try {
Registry myReg = LocateRegistry.getRegistry("192.168.1.5",30);
System.out.println("running...");
CalInterface c= (CalInterface)myReg.lookup("MSA");
WorkInterface w= (WorkInterface)myReg.lookup("Work");
} catch (Exception e) {
e.printStackTrace();
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.