日期:2014-05-19  浏览次数:20730 次

rmi 问题
我用rmi建立一个服务。
如果用1099端口,就可以正常启动
如果用别的端口,就报如下错:
启动参数是 java -jar myclass.jar
我在linux上运行,关闭了iptable

Exception in thread "main" java.rmi.ConnectException: Connection refused to host: 192.168.6.88; nested exception is:
        java.net.ConnectException: Connection refused
        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.bind(Unknown Source)
        at java.rmi.Naming.bind(Naming.java:128)
        at main.RemoteGeneralServer.main(RemoteGeneralServer.java:55)
Caused by: java.net.ConnectException: Connection refused
        at java.net.PlainSocketImpl.socketConnect(Native Method)
        at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:327)
        at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:193)
        at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:180)
        at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:384)
        at java.net.Socket.connect(Socket.java:546)
        at java.net.Socket.connect(Socket.java:495)
        at java.net.Socket.<init>(Socket.java:392)
        at java.net.Socket.<init>(Socket.java:206)
        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)



代码如下:
public static void main(String[] args) throws UnknownHostException, RemoteException,  MalformedURLException, AlreadyBoundException {
RemoteDimGrouperProxyInterface dimGrouperProxyMin = new RemoteDimGrouperProxy();
LocateRegistry.createRegistry(1099);//只能是1099,如果换其他端口都错
Naming.bind("Min", dimGrouperProxyMin);
}

------解决方案--------------------
Naming.rebind("Min", dimGrouperProxyMin);  
//Min要是你新端口,比如: Naming.rebind("//127.0.0.1:10001/queryApp",dimGrouperProxyMin);