Friday, July 16, 2010

Connection refused to host : 127.0.0.1

If you are getting an error when accessing JMX from another machine (linux) like ::

java.rmi.ConnectException: Connection refused to host: ; nested exception is:
java.net.ConnectException: Connection refused: connect
java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:320)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:133)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:120)
at java.net.Socket.(Socket.java:273)
at java.net.Socket.(Socket.java:100)
at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirectSocketFactory.java:25)
at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(RMIMasterSocketFactory.java:120)
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:499)
at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:190)
at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:174)
at sun.rmi.server.UnicastRef.newCall(UnicastRef.java:318)
at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
at java.rmi.Naming.lookup(Naming.java:84)
...(rest is my code)


You should run your service like whatever you want to see through JMX .

-Djava.rmi.server.hostname=your-ip-address

It will run successfully...

Long Live Open Source !!!

2 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. Hello Developer,

    Plz see this socket code..

    Socket s1 = null;
    try {
    s1 = new Socket("192.168.0.127",5675);
    } catch (UnknownHostException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    InputStream s1In = null;
    try {
    s1In = s1.getInputStream();
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    DataInputStream dis = new DataInputStream(s1In);
    String st = null;
    try {
    st = new String (dis.readUTF());
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    System.out.println(st);
    // When done, just close the connection and exit
    try {
    dis.close();
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    try {
    s1In.close();
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    try {
    s1.close();
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }

    i am using above code for socket connection that works for another socket but when using this port and ip, which maintained in code then facing issue:
    java.net.ConnectException: Connection refused: 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.(Unknown Source)
    at java.net.Socket.(Unknown Source)
    at connection2.main(connection2.java:18)
    Exception in thread "main" java.lang.NullPointerException
    at connection2.main(connection2.java:28)

    This socket works on Xcode, i am trying on winXP system.I have already checked firewall all r well setted,Plz share me resign for this issue.What security resign works for socket plz confirm me..
    I am thanking of you.

    ReplyDelete