gpt4 book ai didi

java.rmi.ConnectIOException : non-JRMP server at remote endpoint

转载 作者:太空宇宙 更新时间:2023-11-04 07:16:58 27 4
gpt4 key购买 nike

这是一个简单的RMI程序,但是,当我运行HelloClient.java时,它总是抛出异常。

创建远程接口(interface)

public interface Hello extends Remote {
String sayHello(String name) throws RemoteException;
}

创建远程类

import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
public class HelloImpl extends UnicastRemoteObject implements Hello {

protected HelloImpl() throws RemoteException {
super();
}

@Override
public String sayHello(String name) throws RemoteException {
System.out.println("HelloImpl:" + name);
return name;
}
}

创建服务器:

import java.rmi.RMISecurityManager;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;

public class HelloServer {
public static final int port = 1099;

public static void main(String[] args) {
try {
if (System.getSecurityManager() == null) {
System.setSecurityManager(new RMISecurityManager());
}
Registry registry = LocateRegistry.createRegistry(port);
HelloImpl impl = new HelloImpl();
registry.rebind("//SEJ1T1DYN68BZBF:1099/HelloService", impl);
String[] names = registry.list();
for (String name : names) {
System.out.println(name);
}

} catch (Exception e) {
e.printStackTrace();
}
}
}

创建客户端:

import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;

public class HelloClient {

public static void main(String[] args) {
try {
Registry registry = LocateRegistry.getRegistry();
Hello hello = (Hello) registry
.lookup("//SEJ1T1DYN68BZBF:1099/HelloService");
System.out.println(hello.sayHello("javamaj blog"));
} catch (Exception e) {
e.printStackTrace();
}
}
}

异常(exception)情况是:

java.rmi.ConnectIOException: non-JRMP server at remote endpoint
at sun.rmi.transport.tcp.TCPChannel.createConnection(Unknown Source)
at sun.rmi.transport.tcp.TCPChannel.newConnection(Unknown Source)
at sun.rmi.server.UnicastRef.newCall(Unknown Source)
at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
at HelloClient.main(HelloClient.java:10)

环境:jdk 1.7 +eclipse+window xp

最佳答案

除了 RMI 注册表之外,还有其他东西在客户端主机的端口 1099 上运行。

但是,除非客户端主机和服务器主机是同一主机,否则您无论如何都会查找错误的注册表。您需要使用服务器主机名调用 getRegistry(),这样您就可以在服务器主机上查找注册表:服务器绑定(bind)到的主机。

关于java.rmi.ConnectIOException : non-JRMP server at remote endpoint,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19831569/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com