android - Unable to connect to server. XMPPException No response from server -
i using asmack library android chat on xmpp. below code have used connect server. app not able connect server. xmppexception no response server. can login desktop chat. not able problem is. here code have used.
public class mainactivity extends activity implements messagelistener{ public static final string host = "mail.speedymx.com"; public static final int port = 5222; //public static final string service = "testservice"; public static final string username = "username@speedymx.com"; public static final string password = "password"; private connection connection; /** called when activity first created. */ @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); system.setproperty("java.net.preferipv6addresses", "false"); setcontentview(r.layout.activity_main); connect(); connection.disconnect(); log.i("myactivity", "disconnected server"); } public void connect() { final progressdialog dialog = progressdialog.show(this, "connecting...", "please wait...",false, true ); new thread(new runnable() { @override public void run() { // create connection system.setproperty("smack.debugenabled", "true"); connectionconfiguration connconfig = new connectionconfiguration(host, port); connconfig.setcompressionenabled(true); connconfig.setreconnectionallowed(true); connconfig.setdebuggerenabled(true); if (build.version.sdk_int >= build.version_codes.ice_cream_sandwich) { connconfig.settruststoretype("androidcastore"); connconfig.settruststorepassword(null); connconfig.settruststorepath(null); } else { connconfig.settruststoretype("bks"); string path = system.getproperty("javax.net.ssl.truststore"); if (path == null) path = system.getproperty("java.home") + file.separator + "etc" + file.separator + "security" + file.separator + "cacerts.bks"; connconfig.settruststorepath(path); } connconfig.setsecuritymode(connectionconfiguration.securitymode.enabled); saslauthentication.supportsaslmechanism("plain"); connconfig.setsaslauthenticationenabled(true); connection = new xmppconnection(connconfig); try { connection.connect(); log.i("myactivity","connected "+ connection.gethost()+"connection secured"+ connection.issecureconnection()); } catch(xmppexception e) { log.i("myactivity", "connection error"+e.tostring()); } try { connection.login(username, password); log.i("myactivity","connected "+ connection.getuser()); runonuithread(new runnable() { public void run() { dialog.dismiss(); } }); } catch (xmppexception ex) { log.e("myactivity", "xmpp exception "+ username+ ex.tostring()); connection.disconnect(); log.i("myactivity", "disconnected server"); } `enter code here`catch (exception ee) { log.e("myactivity", ee.tostring()); connection.disconnect(); log.i("myactivity", "disconnected server"); } } }).start(); dialog.show(); presence presence = new presence(presence.type.available); presence.setstatus("available"); presence.setpriority(24); presence.setmode(presence.mode.available); connection.sendpacket(presence); sendmessgage(); private void sendmessgage() { // todo auto-generated method stub try { chat chat = connection.getchatmanager().createchat("samreshs@speedymx.com", this); chat.sendmessage("this test message"); } catch (xmppexception e) { log.i("myactivity","error delivering block"); connection.disconnect(); } } @override public void processmessage(chat arg0, message arg1) { // todo auto-generated method stub log.i("myactivity", "received message "+ arg1); } }
here log additional reference
06-26 11:37:44.558: d/dalvikvm(421): gc_for_alloc freed 31k, 6% free 12337k/12999k, paused 88ms 06-26 11:37:44.568: i/dalvikvm-heap(421): grow heap (frag case) 12.753mb 358108-byte allocation 06-26 11:37:44.650: d/dalvikvm(421): gc_for_alloc freed <1k, 6% free 12686k/13383k, paused 64ms 06-26 11:37:44.837: d/dalvikvm(421): gc_for_alloc freed 215k, 6% free 12649k/13383k, paused 74ms 06-26 11:37:44.847: i/dalvikvm-heap(421): grow heap (frag case) 12.936mb 229392-byte allocation 06-26 11:37:44.937: d/dalvikvm(421): gc_for_alloc freed <1k, 6% free 12872k/13639k, paused 80ms 06-26 11:37:45.068: d/dalvikvm(421): gc_for_alloc freed 129k, 6% free 12858k/13639k, paused 64ms 06-26 11:37:45.068: i/dalvikvm-heap(421): grow heap (frag case) 13.091mb 178704-byte allocation 06-26 11:37:45.168: d/dalvikvm(421): gc_for_alloc freed 0k, 6% free 13032k/13831k, paused 83ms 06-26 11:37:45.318: d/dalvikvm(421): gc_for_alloc freed 98k, 7% free 12934k/13831k, paused 126ms 06-26 11:37:45.338: i/dalvikvm-heap(421): grow heap (frag case) 14.098mb 1155904-byte allocation 06-26 11:37:45.448: d/dalvikvm(421): gc_for_alloc freed 0k, 7% free 14063k/14983k, paused 86ms 06-26 11:37:45.618: d/dalvikvm(421): gc_concurrent freed <1k, 7% free 14063k/14983k, paused 7ms+3ms 06-26 11:37:45.899: d/dalvikvm(421): gc_for_alloc freed <1k, 7% free 14063k/14983k, paused 121ms 06-26 11:37:45.918: i/dalvikvm-heap(421): grow heap (frag case) 16.058mb 2054928-byte allocation 06-26 11:37:46.052: d/dalvikvm(421): gc_for_alloc freed 0k, 6% free 16070k/17031k, paused 71ms 06-26 11:37:46.238: d/dalvikvm(421): gc_concurrent freed <1k, 6% free 16070k/17031k, paused 7ms+13ms 06-26 11:37:46.477: d/androidruntime(421): shutting down vm 06-26 11:37:46.477: w/dalvikvm(421): threadid=1: thread exiting uncaught exception (group=0x40014760) 06-26 11:37:46.508: e/androidruntime(421): fatal exception: main 06-26 11:37:46.508: e/androidruntime(421): java.lang.runtimeexception: unable start activity componentinfo{com.org.chatboss/com.org.chatboss.mainactivity}: java.lang.nullpointerexception 06-26 11:37:46.508: e/androidruntime(421): @ android.app.activitythread.performlaunchactivity(activitythread.java:1748) 06-26 11:37:46.508: e/androidruntime(421): @ android.app.activitythread.handlelaunchactivity(activitythread.java:1764) 06-26 11:37:46.508: e/androidruntime(421): @ android.app.activitythread.access$1500(activitythread.java:122) 06-26 11:37:46.508: e/androidruntime(421): @ android.app.activitythread$h.handlemessage(activitythread.java:1002) 06-26 11:37:46.508: e/androidruntime(421): @ android.os.handler.dispatchmessage(handler.java:99) 06-26 11:37:46.508: e/androidruntime(421): @ android.os.looper.loop(looper.java:132) 06-26 11:37:46.508: e/androidruntime(421): @ android.app.activitythread.main(activitythread.java:4025) 06-26 11:37:46.508: e/androidruntime(421): @ java.lang.reflect.method.invokenative(native method) 06-26 11:37:46.508: e/androidruntime(421): @ java.lang.reflect.method.invoke(method.java:491) 06-26 11:37:46.508: e/androidruntime(421): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:841) 06-26 11:37:46.508: e/androidruntime(421): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:599) 06-26 11:37:46.508: e/androidruntime(421): @ dalvik.system.nativestart.main(native method) 06-26 11:37:46.508: e/androidruntime(421): caused by: java.lang.nullpointerexception 06-26 11:37:46.508: e/androidruntime(421): @ com.org.chatboss.mainactivity.connect(mainactivity.java:263) 06-26 11:37:46.508: e/androidruntime(421): @ com.org.chatboss.mainactivity.oncreate(mainactivity.java:75) 06-26 11:37:46.508: e/androidruntime(421): @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1048) 06-26 11:37:46.508: e/androidruntime(421): @ android.app.activitythread.performlaunchactivity(activitythread.java:1712) 06-26 11:37:46.508: e/androidruntime(421): ... 11 more 06-26 11:37:47.188: d/smack(421): 11:37:47 sent (1087309296): <stream:stream to="mail.speedymx.com" xmlns="jabber:client" xmlns:stream="http://etherx.jabber.org/streams" version="1.0"> 06-26 11:37:47.418: d/smack(421): 11:37:47 rcv (1087309296): <?xml version='1.0'?><stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' id='2134678635' from='speedymx.com' xml:lang='en'><stream:error><host-unknown xmlns='urn:ietf:params:xml:ns:xmpp-streams'/></stream:error></stream:stream> 06-26 11:37:47.488: d/smack(421): 11:37:47 sent (1087309296): <presence id="nreu4-0" type="unavailable"></presence> 06-26 11:37:47.508: i/myactivity(421): connected mail.speedymx.comconnection securedfalse 06-26 11:37:47.518: d/smack(421): 11:37:47 sent (1087309296): <iq id="nreu4-1" type="get"><query xmlns="jabber:iq:auth"><username>username@speedymx.com</username></query></iq> 06-26 11:37:47.528: d/smack(421): 11:37:47 sent (1087309296): </stream:stream> 06-26 11:37:47.678: w/system.err(421): stream:error (host-unknown) 06-26 11:37:47.678: w/system.err(421): @ org.jivesoftware.smack.packetreader.parsepackets(packetreader.java:255) 06-26 11:37:47.678: w/system.err(421): @ org.jivesoftware.smack.packetreader.access$000(packetreader.java:43) 06-26 11:37:47.678: w/system.err(421): @ org.jivesoftware.smack.packetreader$1.run(packetreader.java:69) 06-26 11:37:52.574: e/myactivity(421): xmpp exception no response server.: 06-26 11:37:52.787: i/myactivity(421): disconnected server 06-26 11:37:53.878: i/process(421): sending signal. pid: 421 sig: 9
the important message in log is:
<host-unknown xmlns='urn:ietf:params:xml:ns:xmpp-streams'/>
this because tell server connecting mail.speedymx.com
, server knows speedymx.com
. should set host
correct value.
if xmpp server speedymx.com
in fact running on mail.speedymx.com
, should add srv records indicate that.
Comments
Post a Comment