- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我有一个典型的客户端和服务器情况,我希望客户端能够从服务器上运行的对象调用方法。我使用Java RMI来解决这种情况。
服务器端代码如下,它编译并运行良好:
ServerInt.java
package gpio.control;
import java.rmi.Remote;
import java.rmi.RemoteException;
public interface ServerInt extends Remote{
public void setHeizung(boolean x) throws RemoteException;
public void quitError() throws RemoteException;
public void startPWM(int periode,int pulsbreite,int pulsanzahl) throws RemoteException;
}
ServerImpl.java
package gpio.control;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.RemoteServer;
import java.rmi.server.UnicastRemoteObject;
public class ServerImpl implements ServerInt{
private Model myModel;
public ServerImpl(Model m) throws RemoteException {
myModel = m;
LocateRegistry.createRegistry(1099);
ServerInt stub = (ServerInt) UnicastRemoteObject.exportObject(this, 1099);
RemoteServer.setLog(System.out);
Registry registry = LocateRegistry.getRegistry();
registry.rebind("Server1", stub);
}
@Override
public void setHeizung(boolean x) throws RemoteException {
myModel.setHeizung(x);
}
@Override
public void quitError() throws RemoteException {
myModel.quitError();
}
@Override
public void startPWM(int periode, int pulsbreite, int pulsanzahl) throws RemoteException {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
}
出于测试目的,我还创建了一个小型客户端应用程序,它与服务器应用程序在同一服务器上运行:
客户端.java
package client;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
public class Client {
public static void main(String[] args) throws RemoteException, NotBoundException {
Registry registry = LocateRegistry.getRegistry();
ServerInt serverint = (ServerInt) registry.lookup("rmi://127.0.0.1:1099/Server1");
serverint.setHeizung(true);
}
}
当我现在运行客户端程序时,出现以下错误:客户端错误:
Exception in thread "main" java.rmi.NotBoundException: rmi://localhost:1099/Server1
at sun.rmi.registry.RegistryImpl.lookup(RegistryImpl.java:166)
at sun.rmi.registry.RegistryImpl_Skel.dispatch(Unknown Source)
at sun.rmi.server.UnicastServerRef.oldDispatch(UnicastServerRef.java:410)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:268)
at sun.rmi.transport.Transport$1.run(Transport.java:200)
at sun.rmi.transport.Transport$1.run(Transport.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:196)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:568)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:826)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$241(TCPTransport.java:683)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:682)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:276)
at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:253)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:379)
at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
at client.Client.main(Client.java:12)
服务器错误:
Sep 07, 2016 9:47:04 AM sun.rmi.server.UnicastServerRef logCall
FINER: RMI TCP Connection(1)-127.0.0.1: [127.0.0.1: sun.rmi.registry.RegistryImpl[0:0:0, 0]: void rebind(java.lang.String, java.rmi.Remote)]
Sep 07, 2016 9:47:04 AM sun.rmi.server.UnicastServerRef logCall
FINER: RMI TCP Connection(2)-127.0.0.1: [127.0.0.1: sun.rmi.transport.DGCImpl[0:0:0, 2]: java.rmi.dgc.Lease dirty(java.rmi.server.ObjID[], long, java.rmi.dgc.Lease)]
Sep 07, 2016 9:47:05 AM sun.rmi.server.UnicastServerRef logCall
FINER: RMI TCP Connection(3)-127.0.0.1: [127.0.0.1: sun.rmi.registry.RegistryImpl[0:0:0, 0]: java.rmi.Remote lookup(java.lang.String)]
Sep 07, 2016 9:47:05 AM sun.rmi.server.UnicastServerRef logCallException
FINE: RMI TCP Connection(3)-127.0.0.1: [127.0.0.1] exception:
java.rmi.NotBoundException: rmi://localhost:1099/Server1
at sun.rmi.registry.RegistryImpl.lookup(RegistryImpl.java:166)
at sun.rmi.registry.RegistryImpl_Skel.dispatch(Unknown Source)
at sun.rmi.server.UnicastServerRef.oldDispatch(UnicastServerRef.java:410)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:268)
at sun.rmi.transport.Transport$1.run(Transport.java:200)
at sun.rmi.transport.Transport$1.run(Transport.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:196)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:568)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:826)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$241(TCPTransport.java:683)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:682)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
我在这里做错了什么?
最佳答案
在Client.java中更改
registry.lookup("rmi://127.0.0.1:1099/Server1")
至
registry.lookup("Server1");
关于Java RMI 实现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39446583/
我正在编写一个 RMI 应用程序。 我能够执行 RMI。数据通过 RMI 在客户端和服务器之间传输。 客户端应始终接收/更新服务器端数据。 是否有可能有一个监听器可以将数据更新/修改从服务器传输或通知
我正在使用 JMX-RMI 代理进行消息传递。我有一个 java 程序,它向一组监听器/监听器发送一条具有名称/ID 的消息。根据监听器收到的消息,客户端程序会相应地运行。这篇文章工作正常,但我想知道
我有一个 RMI 服务器,当在本地主机上运行时,它可以正确绑定(bind)到 RMI 注册表(以证明设置正确)。执行此操作的代码是: private void exposeTickHistoryRe
我想获取服务器端每个客户端的 ip 地址,服务器为其返回一个 stub 。是否可以? 最佳答案 请参阅 RemoteServer.getClientHost()。您可以在远程方法实现中调用它。但是,当
我有两个 Java 程序 - RMIServer 和 RMIClient。如果我将它们作为两个单独的 Java 调用启动,一切都会按预期工作。那就是 $ java -cp someclasspath
目前正在阅读有关 RPC 和 RMI 的资料,我对它们之间的区别有点困惑。 在实现 RMI 和 gRPC 时,语法基本相同。 它们都有确定方法参数和响应的接口(interface)。 它们都可以在参数
这个问题在这里已经有了答案: 12年前关闭。 Possible Duplicate: RMI and CORBA Differences? RMI 和 Corba 有什么区别? 最佳答案 RMI 是一
我是 java RMI 的新手,我正在尝试创建一个类似 Peer 2 Peer 的 bit torrent 应用程序,其中同一对等点的多个实例可能位于同一台机器上。这意味着我需要能够在同一台机器上注册
当我尝试运行我的 RMI 示例时出现远程异常。我不明白为什么。我在不对程序本身或 JVM 进行任何参数的情况下运行该程序。 请帮助我摆脱异常。 非常感谢 这是我得到的异常: Server except
关于 Oracle's FAQ page关于 Java RMI,它说: While the Java Remote Method Invocation (Java RMI) server can th
我有一个 java rmi 服务器和一个 java rmi 客户端在两台独立且不同的机器。 服务器基本上是一个斐波那契计算器。它接收一堆数字并根据它们计算斐波那契数列。 客户端只需发送一堆数字供服务器
关闭。此题需要details or clarity 。目前不接受答案。 想要改进这个问题吗?通过 editing this post 添加详细信息并澄清问题. 已关闭 8 年前。 Improve th
我想知道 RMI 中是否可以在与提供服务的服务器不同的主机上启动 RMIregistry。 最佳答案 是的,这是可能的,但不方便,因为bind()、rebind()和unbind()只能从本地主机接受
我在连接客户端类的远程对象时遇到一些问题。当我运行以下客户端类时,我收到 java.rmi.ConnectException。 import java.rmi.registry.LocateRegis
我正在尝试让一台计算机上的客户端通过 Java RMI 与另一台计算机上的服务器通信。我将服务器部署在端口 Y 上的主机 IP X 上。然后,我尝试让客户端查找服务器上的远程对象,但出现以下异常: E
我有一个自定义的 RMIClientSocketFactory,它覆盖“createSocket”来创建一个特殊的套接字。 如何在我的 rmi 远程接口(interface)实现中获取这个套接字? (
我的 RMI Reaper 线程有问题,它不允许我的所有程序终止,因为该线程不是守护进程。我发现信息表明该线程仅在所有对象均未导出时停止。所以我有以下代码来创建 rmi serer。 registry
当我在运行 RMI 服务器后尝试运行 RMI 客户端时,出现以下异常: EncodeInterface exception: java.lang.ClassCastException: $Proxy3
我想为 RMI 客户端应用程序编写一组系统集成测试。我想在 JUnit 3.8.2 中启动 RMI 服务器,然后运行这些测试。有没有人这样做过? 我在带有 main 的 pojo 中使用类似这样的东西
这个问题已经有答案了: java.rmi.ServerException: RemoteException occurred in server thread (ClassNotFoundExcept
我是一名优秀的程序员,十分优秀!