2016-04-13 26 views
1

'a yanıt vermiyor Smack API'yi dizüstü bilgisayarım (localhost) üzerinde kurulu Openfire XMPP sunucusuna bağlanmaya ve oturum açmaya çalışıyorum.Openfire, Smack login()

XMPPTCPConnectionConfiguration conf = XMPPTCPConnectionConfiguration.builder() 
      .setServiceName("win10-xps15") 
      .setHost("192.168.1.100") 
      .setPort(5222) 
      .setCompressionEnabled(false) 
      .setSecurityMode(ConnectionConfiguration.SecurityMode.disabled) 
      .build(); 

    XMPPTCPConnection connection = new XMPPTCPConnection(conf); 

    connection.connect(); 
    connection.login("admin", "password"); 

connect() metodu başarılı ama login() yöntemi, bir NoResponse (zaman aşımı) hariç olmak üzere başarısız olur.

Exception in thread "main" org.jivesoftware.smack.SmackException$NoResponseException: No response received within reply timeout. Timeout was 5000ms (~5s). Used filter: No filter used or filter was 'null'. 
    at org.jivesoftware.smack.SmackException$NoResponseException.newWith(SmackException.java:106) 
    at org.jivesoftware.smack.SmackException$NoResponseException.newWith(SmackException.java:85) 
    at org.jivesoftware.smack.SASLAuthentication.authenticate(SASLAuthentication.java:250) 
    at org.jivesoftware.smack.tcp.XMPPTCPConnection.loginNonAnonymously(XMPPTCPConnection.java:374) 
    at org.jivesoftware.smack.AbstractXMPPConnection.login(AbstractXMPPConnection.java:456) 
    at org.jivesoftware.smack.AbstractXMPPConnection.login(AbstractXMPPConnection.java:431) 
    at MyConnector.main(MyConnector.java:23) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:497) 
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144) 
Apr 13, 2016 11:45:42 AM org.jivesoftware.smack.AbstractXMPPConnection callConnectionClosedOnErrorListener 
WARNING: Connection closed with error 
java.lang.NullPointerException 
    at org.jivesoftware.smack.util.stringencoder.Base64.decode(Base64.java:86) 
    at org.jivesoftware.smack.sasl.SASLMechanism.challengeReceived(SASLMechanism.java:233) 
    at org.jivesoftware.smack.SASLAuthentication.challengeReceived(SASLAuthentication.java:328) 
    at org.jivesoftware.smack.SASLAuthentication.challengeReceived(SASLAuthentication.java:313) 
    at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.parsePackets(XMPPTCPConnection.java:1051) 
    at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.access$300(XMPPTCPConnection.java:948) 
    at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader$1.run(XMPPTCPConnection.java:963) 
    at java.lang.Thread.run(Thread.java:745) 

benim Windows dizüstü bilgisayar ve yerel IP Openfire 3.9.3 çalıştırıyorum 192.168.1.100 olduğunu. Smack kütüphanesinin versiyonu 4.1.6.

Başarısız olan login() yöntemi olduğundan, bilmem gereken oturum açma/kullanıcı ile ilgili herhangi bir Openfire sunucusu ayarının olup olmadığını merak ediyorum? Ayrıca, Spark IM client ile oturum açmayı denedim ve yerel sunucuyu sorunsuz bir şekilde oturum açabiliyordum.

Saygılarımızla.


Daha fazla bilgi aşağıda eklenmiştir.

ConnectionConfiguration conf = 
      new ConnectionConfiguration("192.168.1.100", 5222); 
    XMPPConnection connection = new XMPPConnection(conf); 

    connection.connect(); 
    connection.login("admin", "password"); 

Şimdi kod çalışıyor:

Sadece eski bir sürümünü şaplak aşağıdaki kodla Spark IM github repo elde (3.4.1) çalıştı. Connect() ve login() her ikisi de tamam.

Ama gerçekten, şaplakın son versiyonunun beklediğim gibi çalışmadığını bilmek istiyorum. Çünkü eski sürüm Android'i doğal olarak desteklemezken Android'de smack kullanmayı düşünüyorum.

+0

Smack'in son sürümünü kullanıyorum ve sizin gibi oturum açma işlemini yapıyorum. Koduma şimdi erişemiyorum, 3 saat içinde size yardım etmeye çalışacağım –

cevap

1

bağlantı için bağımlılıkları

compile 'org.igniterealtime.smack:smack-tcp:4.1.0' 
compile 'org.igniterealtime.smack:smack-android-extensions:4.1.0' 
compile 'org.igniterealtime.smack:smack-im:4.1.0' 

2) zaman uyumsuz görev eklemek) aşama

1 adım ile başlar veya sunucu

//connect or login to server 
private class MyOpenfireLoginTask extends AsyncTask<String, String, String> { 
    private Context mContext; 
    String username, password; 
    ProgressDialog dialog; 


    public MyOpenfireLoginTask(Context context) { 
     mContext = context; 
    } 

    @Override 
    protected void onPreExecute() { 
     super.onPreExecute(); 
     dialog = new ProgressDialog(mContext); 
     dialog.setMessage("Loading..."); 
     dialog.setCanceledOnTouchOutside(false); 
     dialog.show(); 
    } 

    @Override 
    protected String doInBackground(String... params) { 

     username = params[0]; 
     password = params[1]; 

     Log.e("Login using ", username + " , " + password); 
     Config.config = XMPPTCPConnectionConfiguration.builder() 
       .setUsernameAndPassword(username, password) 
       .setHost("your host ex- wec.com") 
       .setResource("Android") 
       .setSecurityMode(ConnectionConfiguration.SecurityMode.disabled) 
       .setServiceName("domain name(@) ex- secureserver.net") 
       .setPort("5222") 
       .setDebuggerEnabled(true) 
       .build(); 
     Config.conn1 = new XMPPTCPConnection(Config.config); 

     Config.conn1.setPacketReplyTimeout(5000); 
     try { 
      Config.conn1.connect(); 
      if (Config.conn1.isConnected()) { 
       Log.w("app", "conn done"); 

      } 
      Config.conn1.login(); 


      if (Config.conn1.isAuthenticated()) { 
       Log.w("app", "Auth done"); 

      } else { 
       Log.e("User Not Authenticated", "Needs to Update Password"); 

      } 

     } catch (Exception e) { 
      Log.w("app", e.toString()); 
     } 

     return ""; 
    } 

    @Override 
    protected void onPostExecute(String result) { 


     dialog.dismiss(); 

     if (Config.conn1.isAuthenticated()) { 
      //success 

     } else { 
      Log.e(TAG, "username password wrong"); 

     } 
    } 
} 

3) sınıfının

yukarıda yürütmek için giriş Lets
if (username.length() > 0 && password.length() > 0) { 
     MyOpenfireLoginTask task = new MyOpenfireLoginTask(activity); 
     task.execute(username, password); 
    }