java.rmi.ConnectIOException& java.net.SocketException:对nonsocket:connect的套接字操作

时间:2013-10-22 16:15:50

标签: java exception rmi dht

我是一个意大利人,很抱歉我的BAD英语。

我用Java编写RMI程序,这是连接到RMI服务器的节点代码部分:

try
        {//trying to connect to the Server
        Remote RemoteObject;
        BootstrapServer_Interface serverObject;
        Registry r = LocateRegistry.getRegistry(10001);
        RemoteObject = r.lookup("BOOTSTRAP-SERVER");//THIS IS LINE 52
        serverObject = (BootstrapServer_Interface)RemoteObject;
        //I get an ip as Server's answerw
        System.out.println("Il nodo "+Thread.currentThread()+" si mette in attesa");
        String ipBN = serverObject.start_join_node(fakeip);
        if(ipBN.equals("-1"))
            {System.out.println("Creazione del nodo "+Thread.currentThread()+" fallito");
            return;
            }

但是,有时,程序会遇到此异常:

java.rmi.ConnectIOException: Exception creating connection to: 131.114.43.246; nested exception is: 
    java.net.SocketException: Socket operation on nonsocket: connect
    at sun.rmi.transport.tcp.TCPEndpoint.newSocket(Unknown Source)
    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 StorageNode.run(StorageNode.java:52)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Caused by: java.net.SocketException: Socket operation on nonsocket: connect
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.PlainSocketImpl.doConnect(Unknown Source)
    at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
    at java.net.PlainSocketImpl.connect(Unknown Source)
    at java.net.SocksSocketImpl.connect(Unknown Source)
    at java.net.Socket.connect(Unknown Source)
    at java.net.Socket.connect(Unknown Source)
    at java.net.Socket.<init>(Unknown Source)
    at java.net.Socket.<init>(Unknown Source)
    at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(Unknown Source)
    at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(Unknown Source)
    ... 9 more

这是客户端连接到RMI服务器的代码:

try
            {//scelgo casualmente un dato da cercare        
            //genero il mio indirizzo ip
            fakeip = String.valueOf((int) (Math.random() * 256)) + "."
                    + String.valueOf((int) (Math.random() * 256)) + "."
                    + String.valueOf((int) (Math.random() * 256)) + "."
                    + String.valueOf((int) (Math.random() * 256));
            //creo una Socket UDP con cui contattare il Nodo di Bootstrap
            UDPServiceSocket = scanner.UDPSocket();
            if(UDPServiceSocket==null)
                {System.out.println("Tentativo di creazione socket UDP fallito...");
                *return;}
            int UDPport = UDPServiceSocket.getLocalPort();
            fakeip=fakeip+" UDPport="+UDPport;
            //mi connetto al server tramite RMI
            Remote RemoteObject;
            Registry r = LocateRegistry.getRegistry(10001);
            RemoteObject = r.lookup("BOOTSTRAP-SERVER");//THIS IS LINE 48
            serverObject = (BootstrapServer_Interface)RemoteObject;
            //Ottengo l'ip del Bootstrap Node a cui connettermi
            System.out.println("Il client "+Thread.currentThread()+" si mette in attesa.");         
            ipBN = serverObject.client_search();
            }

在这种情况下的例外情况(不一定与我上面发布的节点异常一起发生)

java.rmi.ConnectIOException: Exception creating connection to: 131.114.43.246; nested exception is: 
    java.net.SocketException: Socket operation on nonsocket: connect
    at sun.rmi.transport.tcp.TCPEndpoint.newSocket(Unknown Source)
    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 Client.run(Client.java:48)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Caused by: java.net.SocketException: Socket operation on nonsocket: connect
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.PlainSocketImpl.doConnect(Unknown Source)
    at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
    at java.net.PlainSocketImpl.connect(Unknown Source)
    at java.net.SocksSocketImpl.connect(Unknown Source)
    at java.net.Socket.connect(Unknown Source)
    at java.net.Socket.connect(Unknown Source)
    at java.net.Socket.<init>(Unknown Source)
    at java.net.Socket.<init>(Unknown Source)
    at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(Unknown Source)
    at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(Unknown Source)

我无法找到导致此异常的任何原因。

我很抱歉之前发布的代码较少,但它只是一个大项目的一小部分,所以我无法通过所有代码:D

但是,如果你需要它,我可以给你一些关于它的信息:

  1. 这是一个DHT项目,这是他尝试时的节点代码     联系Bootstrap服务器(实际上是一个RMI服务器)。

  2. RMI服务器方法可以由许多节点(上面的代码)和/或调用     许多客户同时。

  3. 节点调用的服务器方法     和/或创建客户端以管理安装在其上的监视器     服务器。
  4. 通过此监视器,节点和客户端修改哈希     表格遵循&#34;作家和读者的模型&#34; (相互排斥     ECC)。
  5. 非常感谢所有帮助我解决这个问题的人,并且再次抱歉我的英语不好!

0 个答案:

没有答案