I am using smack libary to connect ejabberd
xmpp
server, I have hosted ejabberd in my locally . And it works fine, I can connect, send text message . The code I used to connect is following
public static final String HOST = "remote_host_ip_address";
public static final int PORT = 5222;
public static final int CONNECT_TIME_OUT = 20000;
public static final String RESOURCE = "Smack";
XMPPTCPConnectionConfiguration.Builder configBuilder = XMPPTCPConnectionConfiguration.builder();
configBuilder.setHost(HOST);
configBuilder.setPort(PORT);
//configBuilder.setServiceName("localhost");
configBuilder.setServiceName("hostname.com");
configBuilder.setResource(RESOURCE);
configBuilder.setCompressionEnabled(true);
configBuilder.setConnectTimeout(CONNECT_TIME_OUT);
//configBuilder.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled);
connectionConfig = configBuilder.build();
connection = new XMPPTCPConnection(connectionConfig);
accountManager = AccountManager.getInstance(connection);
chatManager = ChatManager.getInstanceFor(connection);
chatManager.addChatListener(chatManagerListener);
When I assign HOST
value to my local ip address like 192.168.101.1 and use configBuilder.setServiceName("localhost");
it works perfect but if I assign configBuilder.setServiceName("hostname.com");
and HOST
variable to remote server ip address it throws the following error
org.jivesoftware.smack.SmackException: javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
But if use any xmpp client like gajim
I can connect to remote server. I have used the following dependencies
compile 'org.igniterealtime.smack:smack-android-extensions:4.1.3'
compile 'org.igniterealtime.smack:smack-tcp:4.1.3'