gpt4 book ai didi

java - 运行 rmi 测试程序时出错

转载 作者:行者123 更新时间:2023-12-02 07:41:07 25 4
gpt4 key购买 nike

我尝试运行以下两个类,但收到此错误。
有谁知道问题出在哪里吗?

java.rmi.ConnectException: Connection refused to host: 10.0.0.2; nested exception is: 
java.net.ConnectException: Connection refused: connect
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:619)
at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:216)
at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:202)
at sun.rmi.server.UnicastRef.newCall(UnicastRef.java:340)
at sun.rmi.registry.RegistryImpl_Stub.rebind(Unknown Source)
at RegisterWithRMIServer.main(RegisterWithRMIServer.java:9)
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:69)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:157)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:391)
at java.net.Socket.connect(Socket.java:579)
at java.net.Socket.connect(Socket.java:528)
at java.net.Socket.<init>(Socket.java:425)
at java.net.Socket.<init>(Socket.java:208)
at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirectSocketFactory.java:40)
at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(RMIMasterSocketFactory.java:146)
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:613)
... 5 more




import java.rmi.registry.*;

public class RegisterWithRMIServer {
/** Main method */
public static void main(String[] args) {
try {
StudentServerInterface obj = new StudentServerInterfaceImpl();
Registry registry = LocateRegistry.getRegistry();
registry.rebind("StudentServerInterfaceImpl", obj);
System.out.println("Student server " + obj + " registered");
}
catch (Exception ex) {
ex.printStackTrace();
}
}
}

///////

import java.rmi.*; 
import java.rmi.server.*;
import java.util.*;

public class StudentServerInterfaceImpl extends UnicastRemoteObject
implements StudentServerInterface {
// Stores scores in a map indexed by name
private HashMap<String, Double> scores =
new HashMap<String, Double>();

public StudentServerInterfaceImpl() throws RemoteException {
initializeStudent();
}

/** Initialize student information */
protected void initializeStudent() {
scores.put("John", new Double(90.5));
scores.put("Michael", new Double(100));
scores.put("Michelle", new Double(98.5));
}

/** Implement the findScore method from the
* Student interface */
public double findScore(String name) throws RemoteException {
Double d = (Double)scores.get(name);

if (d == null) {
System.out.println("Student " + name + " is not found ");
return -1;
}
else {
System.out.println("Student " + name + "\'s score is " + d.doubleValue());
return d.doubleValue();
}
}
}

最佳答案

您是否启动了注册表。这里有一个关于RMI的简短链接

RMI Tutorial (Running RMI programs)

要在 Windows 上启动注册表(如果您的操作系统是 Windows),您需要打开命令提示符并键入

start rmiregistry

如果您的操作系统是 Solaris 或 Linux

rmiregistry &

关于java - 运行 rmi 测试程序时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11573482/

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