0
我是一個初學NetBeans和Java的人,所以我很確定我的問題是非常基本的,但試圖找到解決方案2周我完全堅持java.rmi.ConnectException:連接拒絕主機:192.168.0.55
這就是問題所在:
我想實現一個RMI服務器的客戶端應用程序 所以第一步是與NetBeans試圖讓從網上
我使用的Oracle教程有一個工作第一部分實施 http://docs.oracle.com/javase/tutorial/rmi/server.html
我的問題不在於客戶端不連接,而是服務器甚至無法註冊到我給他的端口。錯誤消息中的IP是我的私有IP。
這是錯誤消息我得到:
Conectando a: 127.0.0.1/19400/PlanificadorTalsa
ServidorPlanificadorStarter exception:
java.rmi.ConnectException: Connection refused to host: 192.168.0.55; 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:342)
at sun.rmi.registry.RegistryImpl_Stub.rebind(Unknown Source)
at Starter.ServidorPlanificadorStarter.main(ServidorPlanificadorStarter.java:52)
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:79)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:345)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at java.net.Socket.connect(Socket.java:538)
at java.net.Socket.<init>(Socket.java:434)
at java.net.Socket.<init>(Socket.java:211)
at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirectSocketFactory.java:40)
at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(RMIMasterSocketFactory.java:148)
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:613)
... 5 more
我運行Windows 8.1,和殘疾人防火牆。我也使用了安全文件授予的所有權限
這是我的Java代碼,我從NetBeans中執行:
import Conexion.DatosConexion;
import Servidor.*;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;
public class ServidorPlanificadorStarter implements InterfazServidorPlanificador {
private static String ip;
private static String Servidor = "SERVIDORNUBE";
private static int puerto;
private static String nombreServidor;
public ServidorPlanificadorStarter(){
super();
}
public static void main(String[] args) {
if (System.getSecurityManager() == null) {
System.setSecurityManager(new SecurityManager());
}
try {
DatosConexion datos = DatosConexion.getInstance();
ip = datos.getServiceIP(Servidor);
puerto = Integer.valueOf(datos.getServicePort(Servidor));
nombreServidor = datos.getServiceName(Servidor);
System.setProperty("java.rmi.server.hostname", ip);
System.out.println("Conectando a: " + ip + "/" + puerto + "/" + nombreServidor);
InterfazServidorPlanificador engine = new ServidorPlanificadorStarter();
InterfazServidorPlanificador stub =
(InterfazServidorPlanificador) UnicastRemoteObject.exportObject(engine, puerto);
Registry registry = LocateRegistry.getRegistry();
registry.rebind(nombreServidor, stub);
System.out.println("ServidorPlanificador bound");
} catch (Exception e) {
System.err.println("ServidorPlanificadorStarter exception:");
e.printStackTrace();
}
}
}
的界面如下(很基本的,因爲我已經做了與它無關)
public interface InterfazServidorPlanificador extends Remote {
//void addObserver(RemoteObserver o) throws RemoteException;
}
找到解決方案。問題出在註冊表中。在定位之前必須先創建。簡單的解決方案,當你不知道時很難找到它。謝謝! – 2015-03-03 12:29:40