Only "localhost" worked when I try to create a connection?

Issue #121 closed
Former user created an issue

Hi, I just try to use babbler and try the sample code with very simple setting. But I found only "localhost" is worked on my sample. I can use PSI to connect to my ejabberd server in the same machine or other machine. But I always got unknownhost error or connection blocked when I change the host value from "localhost" to "127.0.0.1" or "192.168.4.44". ...etc. All these value is worked on PSI. So there might not be the network problem.

Are there any possible reason make this happened?

Thank you~~

Eric

                    String host = "localhost";

                    TcpConnectionConfiguration tcpConfiguration = TcpConnectionConfiguration.builder()
                        .hostname(host)
                        .port(5222)
                        .secure(false) 
                        .build();

                    XmppClient xmppClient = XmppClient.create(host, tcpConfiguration);

                // Listen for inbound messages.
                xmppClient.addInboundMessageListener(e -> logger.info("Received: " + e.getMessage()));

                // Listen for inbound presence.
                xmppClient.addInboundPresenceListener(e -> logger.info("Received: " + e.getPresence()));

                // Connect
                xmppClient.connect();

Comments (5)

  1. Christian Schudt repo owner

    Hi. What's the error message?

    I suspect the mistake is, that you are using the "host" for the domain, i.e. in the XmppClient.create() method. E.g. you domain might be something like "myserver.com" and you hostname might be "192.168.4.44".

    If you are using the IP address for the domain, it probably fails. Check, on which domain your server is running (or configured for).

    Or try to pass null instead of host

  2. Eric Peng

    I have add the entry

    192.168.4.44 Eric-MBP.company.com

    in my hosts.

    The result is similiar. The Tcp connection fine but error when read XML stream.

    I have traced, the error casued by following function: TcpConnection:connect --> xmppStreamReader.startReading(inputStream); //(last line.) The error triggered by the while loop in startReading.

    Setting:

    TcpConnectionConfiguration tcpConfiguration = TcpConnectionConfiguration.builder()
             .hostname("192.168.4.44") // The hostname.
             .port(5222) // The XMPP default port.
             .secure(false) // We want to negotiate a TLS connection.
             .build();
    
    XmppClient xmppClient = XmppClient.create("Eric-MBP.company.com", tcpConfiguration);
    

    Result:

    2017/11/22 上午 9:33 FINE  Connected via TCP connection to 192.168.4.44:5222 (16138359463219932738)
    2017/11/22 上午 9:33 FINE  Negotiating stream, waiting until SASL is ready to be negotiated.
    rocks.xmpp.core.stream.StreamErrorException: host-unknown
        at rocks.xmpp.core.session.XmppSession.handleElement(XmppSession.java:1204)
        at rocks.xmpp.core.session.XmppStreamReader.lambda$0(XmppStreamReader.java:185)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
        at java.lang.Thread.run(Unknown Source)
    rocks.xmpp.core.stream.StreamErrorException: host-unknown
        at rocks.xmpp.core.session.XmppSession.handleElement(XmppSession.java:1204)
        at rocks.xmpp.core.session.XmppStreamReader.lambda$0(XmppStreamReader.java:185)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
        at java.lang.Thread.run(Unknown Source)
    

    Setting:

    TcpConnectionConfiguration tcpConfiguration = TcpConnectionConfiguration.builder()
        .hostname("192.168.4.44") // The hostname.
            .port(5222) // The XMPP default port.
            .secure(false) // We want to negotiate a TLS connection.
            .build();
    
    XmppClient xmppClient = XmppClient.create("192.168.4.44", tcpConfiguration);
    

    Result:

    rocks.xmpp.core.stream.StreamErrorException: host-unknown
        at rocks.xmpp.core.session.XmppSession.handleElement(XmppSession.java:1204)
        at rocks.xmpp.core.session.XmppStreamReader.lambda$0(XmppStreamReader.java:185)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
        at java.lang.Thread.run(Unknown Source)
    2017/11/22 上午 9:34 FINE  Connected via TCP connection to 192.168.4.44:5222 (11071295851153370852)
    2017/11/22 上午 9:34 FINE  Negotiating stream, waiting until SASL is ready to be negotiated.
    rocks.xmpp.core.stream.StreamErrorException: host-unknown
        at rocks.xmpp.core.session.XmppSession.handleElement(XmppSession.java:1204)
        at rocks.xmpp.core.session.XmppStreamReader.lambda$0(XmppStreamReader.java:185)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
        at java.lang.Thread.run(Unknown Source)
    

    Setting:

    TcpConnectionConfiguration tcpConfiguration = TcpConnectionConfiguration.builder()
        .hostname("192.168.4.44") // The hostname.
            .port(5222) // The XMPP default port.
            .secure(false) // We want to negotiate a TLS connection.
            .build();
    
    XmppClient xmppClient = XmppClient.create(null, tcpConfiguration);
    

    Result:

    2017/11/22 上午 9:38 FINE  Connected via TCP connection to 192.168.4.44:5222
    2017/11/22 上午 9:38 FINE  Negotiating stream, waiting until SASL is ready to be negotiated.
    Exception in thread "pool-1-thread-1" java.lang.NullPointerException
    javax.xml.stream.XMLStreamException: java.net.SocketException: Socket closed
        at java.util.Objects.requireNonNull(Unknown Source)
        at rocks.xmpp.core.stream.model.StreamHeader.initialClientToServer(StreamHeader.java:159)
        at rocks.xmpp.core.session.XmppStreamWriter.lambda$2(XmppStreamWriter.java:165)
        at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
        at java.util.concurrent.FutureTask.run(Unknown Source)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(Unknown Source)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
        at java.lang.Thread.run(Unknown Source)
        at com.sun.org.apache.xerces.internal.impl.XMLStreamReaderImpl.setInputSource(Unknown Source)
        at com.sun.org.apache.xerces.internal.impl.XMLStreamReaderImpl.<init>(Unknown Source)
        at com.sun.xml.internal.stream.XMLInputFactoryImpl.getXMLStreamReaderImpl(Unknown Source)
        at com.sun.xml.internal.stream.XMLInputFactoryImpl.createXMLStreamReader(Unknown Source)
        at com.sun.xml.internal.stream.XMLInputFactoryImpl.createXMLEventReader(Unknown Source)
        at rocks.xmpp.core.session.XmppStreamReader.lambda$0(XmppStreamReader.java:113)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
        at java.lang.Thread.run(Unknown Source)
    Caused by: java.net.SocketException: Socket closed
        at java.net.SocketInputStream.socketRead0(Native Method)
        at java.net.SocketInputStream.socketRead(Unknown Source)
        at java.net.SocketInputStream.read(Unknown Source)
        at java.net.SocketInputStream.read(Unknown Source)
        at java.io.BufferedInputStream.fill(Unknown Source)
        at java.io.BufferedInputStream.read(Unknown Source)
        at com.sun.org.apache.xerces.internal.impl.XMLEntityManager$RewindableInputStream.read(Unknown Source)
        at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.setupCurrentEntity(Unknown Source)
        at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.startEntity(Unknown Source)
        at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.startDocumentEntity(Unknown Source)
        at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.setInputSource(Unknown Source)
        ... 9 more
    
  3. Eric Peng

    Hi,

    I found the reason finally, I got wrong assumption for the domain name in XmppClient.create, after I replace the domain name to the name in the ejabberd.yml's host setting. The connection worked. Thank you~~~

  4. Log in to comment