I am following a quick guide from Smack Documentation, for me to connect my asmack xmpp client with openfire xmpp server. But unfortunately, there a exception errors that I got from following the codes on smack documentation.
Since that I am not actually using smack but instead I am using asmack (smack version for android), I read from here that I should call SmackAndroid.init(Context)
in order to initialize Smack on Android or Smack won't work as expected.
I aslo build add and dnsjava library, for me to execute this single line of code SmackAndroid.init(Context)
. I Thought that these steps will solve my problem upon connecting asmack client with openfire server but its not.
Here is my code:
public class MainActivity extends Activity {
public static final String HOST = "Kirbys-Mac-mini.local";
public static final int PORT = 5222;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
new ConnectToServer().execute();
}
private class ConnectToServer extends AsyncTask <Void, Void, Void>{
@Override
protected Void doInBackground(Void... params) {
// TODO Auto-generated method stub
SmackAndroid.init(MainActivity.this);
boolean isConnected = false;
ConnectionConfiguration config = new ConnectionConfiguration(HOST, PORT);
XMPPConnection conn2 = new XMPPTCPConnection(config);
try {
conn2.connect();
isConnected = true;
}
catch (IOException e){
Log.e("XMPPIOExceptionj", e.toString());
} catch (SmackException e){
Log.e("XMPPSmackException", e.toString()+" Host:"+conn2.getHost()+"Port:"+conn2.getPort());
} catch (XMPPException e){
Log.e("XMPPChatDemoActivity", "Failed to connect to "+ conn2.getHost());
Log.e("XMPPChatDemoActivity", e.toString());
}
return null;
}
After I run the application, Errors will show up in my logcat because there is something wrong happened while connecting to my server. These are the error that was catched by the exception:
11-26 04:24:19.783: E/XMPPSmackException(3964): org.jivesoftware.smack.SmackException$ConnectionException Host:nullPort:0
I don't now why is this happening to my app. Even the way that I setup my openfire is on default and I also use its embedded database. Please help me with my problem.