Project

General

Profile

How to solve "java.net.SocketException: Connection reset" when using tigase.jaxmpp.j2se.Jaxmpp 3.0.0

Mahesh Kumaraguru
Added about 3 years ago

I have written a JAXMPPClient.java program which uses tigase.jaxmpp.j2se.Jaxmpp 3.0.0

I have the following .jsr files in my build path

jaxmpp-core-3.0.0

jaxmpp-j2se-3.0.0

and folder jaxmpp-all-3.0.0 containing many .jar files. The JAXMPPClient.java is as follows

    Jaxmpp conn = new Jaxmpp();
    conn.getConnectionConfiguration().setConnectionType(ConnectionType.socket);
    conn.getConnectionConfiguration().setDomain(IP_ADDRESS_OF_XMPP_SERVER);
    conn.getConnectionConfiguration().setPort(PORT_NUMBER_OF_XMPP_SERVER);
    conn.getConnectionConfiguration().setUserJID(FROM_USERID + "@" + IP_ADDRESS_OF_XMPP_SERVER);
    conn.getConnectionConfiguration().setUserPassword(FROM_PASSWORD);

    conn.getSessionObject().setProperty(
        tigase.jaxmpp.j2se.connectors.socket.SocketConnector.HOSTNAME_VERIFIER_DISABLED_KEY, 
        Boolean.TRUE);

    try {
      System.out.println("Before login");
      conn.login();
      System.out.println("After login");
    } catch (final JaxmppException e) {
      e.printStackTrace();
    }

I am getting

= = = = = = = = = = = =

Before login
Sep 29, 2015 5:17:12 PM tigase.jaxmpp.j2se.Jaxmpp createConnector
INFO: Using SocketConnector
Sep 29, 2015 5:17:12 PM tigase.jaxmpp.j2se.connectors.socket.SocketConnector start
INFO: Resolving SRV recrd of domain '123.45.678.910'
Sep 29, 2015 5:17:12 PM tigase.jaxmpp.j2se.connectors.socket.SocketConnector start
INFO: Opening connection to /123.45.678.910:5222
Sep 29, 2015 5:17:12 PM tigase.jaxmpp.j2se.connectors.socket.Worker run
WARNING: Exception in worker
java.net.SocketException: Connection reset
    at java.net.SocketInputStream.read(SocketInputStream.java:209)
    at java.net.SocketInputStream.read(SocketInputStream.java:141)
    at tigase.jaxmpp.j2se.connectors.socket.TextStreamReader.read(TextStreamReader.java:49)
    at tigase.jaxmpp.j2se.connectors.socket.Worker.run(Worker.java:99)

After login

= = = = = = = = = = = =

The IP Address, Port number, From JabberID and Password are correct and are working find from iOS and Android Apps. Also I am able to successfully ping the Tigase server IP address.

From where is the java.net.SocketException being thrown ? How can I fix this problem ?

Thanks and Regards,

Mahesh Kumaraguru


Replies (1)

Added by Wojciech Kapcia TigaseTeam almost 3 years ago

The problem is in your code/using IPs instead of domains and considering them equal.

You are calling:

conn.getConnectionConfiguration().setDomain(IP_ADDRESS_OF_XMPP_SERVER);

so JaXMPP would try to resolve this domain and then try to establish connection. Above is not needed acctualy as the domain is derived from the JID, which you provide later on.

If you want to configure explice machine address you should use:

conn.getProperties().setUserProperty( SocketConnector.SERVER_HOST, IP_ADDRESS_OF_XMPP_SERVER );

    (1-1/1)