Smack 4.1 No Response within reply timeout
Asked Answered
S

3

10

I am using the following code in my android app:

Thread d = new Thread(new Runnable() {

    @Override
    public void run() {
        SmackConfiguration.setDefaultPacketReplyTimeout(10000);
        XMPPTCPConnectionConfiguration config = XMPPTCPConnectionConfiguration.builder()
                  .setUsernameAndPassword("admin", "password")
                  .setServiceName("192.168.0.200")
                  .setHost("192.168.0.200")
                  .setPort(5223).setSecurityMode(SecurityMode.ifpossible)
                  .build();

        AbstractXMPPConnection conn2 = new XMPPTCPConnection(config);
        try {
            conn2.connect();
            conn2.login();

            Presence presence = new Presence(Presence.Type.unavailable);
            presence.setStatus("Gone fishing");
            // Send the packet (assume we have an XMPPConnection instance called "con").
            conn2.sendStanza(presence);

        } catch (SmackException | IOException | XMPPException e) {
            e.printStackTrace();
            Log.d("TAG", e.toString());
        }

        ChatManager chatmanager = ChatManager.getInstanceFor(conn2);
        Chat newChat = chatmanager.createChat("[email protected]");

        try {
            newChat.sendMessage("Howdy!");
        }
        catch (NotConnectedException e) {
            e.printStackTrace();
        }
    }
});

d.start();

This is returning this error:

05-14 18:07:48.030: D/TAG(19470): org.jivesoftware.smack.SmackException$NoResponseException: No response received within reply timeout. Timeout was 10000ms (~10s). Used filter: No filter used or filter was 'null'.

I have set up a local server at 192.168.0.200. Could anybody tell me what the problem is?

I am using these libraries:

enter image description here

Supinate answered 14/5, 2015 at 12:41 Comment(3)
Where you able to solve this issue? I am facing the same problem atmDiandiana
did you solved it ?Nolpros
@Supinate any solution?Tonedeaf
T
4

I have successfully connected to local openfire server and logged in without SSL. Here is my code

public class NewClientActivity extends Activity {
    EditText etUsername, etPassword;
    Button bSubmit;
    AbstractXMPPConnection mConnection;
    ConnectionListener connectionListener = new ConnectionListener() {
        @Override
        public void connected(XMPPConnection xmppConnection) {
            Log.d("xmpp", "connected");
            try {
                SASLAuthentication.registerSASLMechanism(new SASLMechanism() {
                    @Override
                    protected void authenticateInternal(CallbackHandler callbackHandler) throws SmackException {

                    }

                    @Override
                    protected byte[] getAuthenticationText() throws SmackException {
                        byte[] authcid = toBytes('\u0000' + this.authenticationId);
                        byte[] passw = toBytes('\u0000' + this.password);
                        return ByteUtils.concact(authcid, passw);
                    }

                    @Override
                    public String getName() {
                        return "PLAIN";
                    }

                    @Override
                    public int getPriority() {
                        return 410;
                    }

                    @Override
                    public void checkIfSuccessfulOrThrow() throws SmackException {

                    }

                    @Override
                    protected SASLMechanism newInstance() {
                        return this;
                    }
                });
                mConnection.login();
            } catch (XMPPException e) {
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        Toast.makeText(NewClientActivity.this, "Incorrect username or password", Toast.LENGTH_LONG).show();
                    }
                });
                e.printStackTrace();
            } catch (SmackException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        @Override
        public void authenticated(XMPPConnection xmppConnection, boolean b) {
            Log.d("xmpp", "authenticated");
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    Toast.makeText(NewClientActivity.this,"Logged in successfully...",Toast.LENGTH_LONG ).show();
                }
            });
        }

        @Override
        public void connectionClosed() {
            Log.d("xmpp", "connection closed");
        }

        @Override
        public void connectionClosedOnError(Exception e) {
            Log.d("xmpp", "cononection closed on error");
        }

        @Override
        public void reconnectionSuccessful() {
            Log.d("xmpp", "reconnection successful");
        }

        @Override
        public void reconnectingIn(int i) {
            Log.d("xmpp", "reconnecting in " + i);
        }

        @Override
        public void reconnectionFailed(Exception e) {
            Log.d("xmpp", "reconnection failed");
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_new_client);
        findViews();
    }

    private void findViews() {
        etUsername = (EditText) findViewById(R.id.etUsername);
        etPassword = (EditText) findViewById(R.id.etPassword);
        bSubmit = (Button) findViewById(R.id.bSubmit);
        bSubmit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String[] params = new String[]{etUsername.getText().toString(), etPassword.getText().toString()};
                new Connect().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, params);
            }
        });
    }

    class Connect extends AsyncTask<String, Void, Void> {
        @Override
        protected Void doInBackground(String... params) {

            XMPPTCPConnectionConfiguration config = null;
            XMPPTCPConnectionConfiguration.Builder builder = XMPPTCPConnectionConfiguration.builder();
            builder.setServiceName("192.168.1.60").setHost("192.168.1.60")
                    .setDebuggerEnabled(true)
                    .setPort(5222)
                    .setUsernameAndPassword(params[0], params[1])
                    .setSecurityMode(ConnectionConfiguration.SecurityMode.disabled)
                    .setCompressionEnabled(false);
            config = builder.build();

            mConnection = new XMPPTCPConnection(config);
            try {
                //mConnection.setPacketReplyTimeout(10000);
                mConnection.addConnectionListener(connectionListener);
                mConnection.connect();
            } catch (SmackException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            } catch (XMPPException e) {
                e.printStackTrace();
            }
            return null;
        }
    }
}
Turtleback answered 3/11, 2015 at 9:25 Comment(6)
Thanks downvoter.. Have you ever used smack 4.1 or tried my solution.Turtleback
maybe somebody wants to connect with security port (SSL). what would be the solution ?Hateful
@GopalSinghSirvi Hey boss!! Your code is just an ISRO rocket. Worked in the first shot itself. Thanks. would you please help me to create a group if your time allows..!!Kenwee
Thanks @RethinavelPillai see updated answer here.. #28281867Turtleback
@GopalSinghSirvi Bro, I asked for MultiUserChat, I just done it. I want you to help me with sharing media in ChatRoom, Thanks for your updated answer.Kenwee
For media sharing upload media via http to custom folder of your server and then embed the link in the chat message. If you send file via xmpp then user must be online to receive the file. see the link ejabberd.im/node/21491Turtleback
C
3

I just removed .setPort from my request and it worked :

private class MyLoginTask extends AsyncTask<String, String, String> {
    @Override
    protected String doInBackground(String... params) {
        // Create a connection to the jabber.org server.
        XMPPTCPConnectionConfiguration config = XMPPTCPConnectionConfiguration.builder()
        .setSecurityMode(ConnectionConfiguration.SecurityMode.disabled)
                .setUsernameAndPassword(USERNAME, PASSWORD)
                .setHost(HOST)
                //.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled)
                .setServiceName(HOST)
                .setDebuggerEnabled(true) // to view what's happening in detail
                .build();

        AbstractXMPPConnection conn1 = new XMPPTCPConnection(config);
        conn1.setPacketReplyTimeout(30000);
        try {
            conn1.connect();
            if(conn1.isConnected()) {
                Log.w("app", "conn done");
            }
            conn1.login();

            if(conn1.isAuthenticated()) {
                Log.w("app", "Auth done");
            }
        }
        catch (Exception e) {
            Log.w("app", e.toString());
        }

        return "";
    }

    @Override
    protected void onPostExecute(String result) {
    }    
}
Chorography answered 20/1, 2017 at 9:15 Comment(1)
removing setport is not a solution but disabling securtity config solved the issue. If you are using https port is 5223 and non ssl 5222 as default. if you are not using ssl then you should say .setSecurityMode(ConnectionConfiguration.SecurityMode.disabled)Sporocarp
H
-2

Try this :

public static void main(String[] args) throws IOException, XMPPException, SmackException, NoSuchAlgorithmException {
    XMPPTCPConnectionConfiguration config = XMPPTCPConnectionConfiguration.builder()
            .setServiceName("olx.intr")
            .setDebuggerEnabled(true)
            .setSecurityMode(ConnectionConfiguration.SecurityMode.disabled)
            .setHost("10.2.2.107")
            .setPort(5222)
            .setUsernameAndPassword("dhiren","olxindia")
            .build();

    AbstractXMPPConnection conn2 = new XMPPTCPConnection(config);
    conn2.connect();
    SASLMechanism mechanism = new SASLDigestMD5Mechanism();
    SASLAuthentication.registerSASLMechanism(mechanism);
    SASLAuthentication.blacklistSASLMechanism("SCRAM-SHA-1");
    SASLAuthentication.unBlacklistSASLMechanism("DIGEST-MD5");
    try {
        conn2.login();
    }catch (Exception e){
        e.printStackTrace();
    }
    boolean authenticated = conn2.isAuthenticated();
    System.out.println(authenticated);
}
Heuristic answered 13/1, 2017 at 14:30 Comment(1)
Why should the OP "try this code"? A good answer will always have an explanation of what was done and why it was done in such a manner, not only for the OP but for future visitors to SO.Embrue

© 2022 - 2024 — McMap. All rights reserved.