java rmi执行的时候遇到的问题,大家帮帮忙??
服务器端
//客户端
服务器启动后,第二次打开客户端会报错;监听1099端口会发现,会生成两个环路进程造成报错,不知道怎么回事,有的电脑就不会报错。求解。
package org.ngweb.rmi;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
/**
* The implementation class of the remote method defined in interface
*
* @author Huangng
*
*/
public class Rmi extends UnicastRemoteObject implements RmiInterface {
private static final long serialVersionUID = 1L;
// The constructor have to throw RemoteException
public Rmi() throws RemoteException {
}
// The implemented remote method.
public String say(String name) throws RemoteException {
System.out.println("Called by HelloClient");
return "Hello, " + name;
}
}
package org.ngweb.rmi;
import java.rmi.Remote;
import java.rmi.RemoteException;
/**
*
* An interface that define the remote method, which should be in both server
* and client end.
*
* @author Huangng
*
*/
public interface RmiInterface extends Remote {
// Any remote method have to throw RemoteException
public String say(String name) throws RemoteException;
}
package org.ngweb.rmi;
import java.rmi.Naming;
import java.rmi.registry.LocateRegistry;
/**
*
* Java RMI server
*
* @author Huangng
*
*/
public class RmiServer {
public static void main(String[] argv) {
try {
// set port number to 1099
LocateRegistry.createRegistry(1099);
// The instance of class with remote method
RmiInterface hello = new Rmi();
// Register the instance
Naming.rebind("Hello", hello);
System.out.println("Starting RMI Server success.");
} catch (Exception e) {
System.out.println("Starting RMI Server failed: " + e);
}
}
}
//客户端
package org.ngweb.rmi;
import java.rmi.Naming;
/**
*
* A client end of Java RMI
*
* @author Huangng
*
*/
public class RmiClient {
public static void main(String[] argv) {
try {
// Find an instance of Hello in remote machine
RmiInterface hello = (RmiInterface) Naming
.lookup("//127.0.0.1:1099/Hello");
// Call remote method
System.out.println(hello.say("huang"));
} catch (Exception e) {
System.out.println("RMI Client exception: " + e);
}
}
}
package org.ngweb.rmi;
import java.rmi.Remote;
import java.rmi.RemoteException;
/**
*
* An interface that define the remote method, which should be in both server
* and client end.
*
* @author Huangng
*
*/
public interface RmiInterface extends Remote {
// Any remote method have to throw RemoteException
public String say(String name) throws RemoteException;
}
服务器启动后,第二次打开客户端会报错;监听1099端口会发现,会生成两个环路进程造成报错,不知道怎么回事,有的电脑就不会报错。求解。
...全文
相关推荐
Java RMI实验
RMI将调用转发到服务器端的`StudentImpl`实例。5. `StudentImpl`执行查询操作并返回结果。6. 结果通过RMI返回给客户端,显示给用户。
Java RMI 例子 和一些常见问题
以下是对Java RMI的详细解释以及一些常见问题的解答。### 1. RMI基本概念RMI的核心是远程接口(Remote Interface),它定义了可以在远程对象上调用的方法。
Rmi.rar_Java RMI_RMI java_java RMI 线程_rmi
Java RMI(Remote Method Invocation)是Java平台提供的一种分布式计算技术,它允许一个Java对象调用网络另一端的Java对象的方法,仿佛它们在同一个进程中执行。
RMI.rar_Java RMI_java.rmi_java.rmi.Remot_remote
然而,在JDK 1.2及以后的版本中,这些组件已经自动由Java编译器生成,不再需要程序员手动编写。此外,RMI还涉及到安全性问题,因为远程对象可能会执行敏感操作。
java rmi java rmi
### RMI的概念RMI是一种Java技术,它允许开发者创建分布式应用程序,其中Java对象可以在网络的不同节点之间进行通信。


