1

I am developing one chat application , But it not work properly, giving different-differet error like 406 or 407 , So please advice me My following code for that is proper or not ,

First Login When Application Start :

  public void LoginWithUser() {

    Thread t = new Thread(new Runnable() {

        @Override
        public void run() {

            SASLAuthentication.unregisterSASLMechanism("org.jivesoftware.smack.sasl.javax.SASLDigestMD5Mechanism");
            SmackInitialization initialization = new SmackInitialization();
            XMPPTCPConnectionConfiguration.Builder config = XMPPTCPConnectionConfiguration.builder();

                config.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled);
                config.setServiceName(Constants.SERVICE);
                config.setHost(Constants.HOST);
                config.setPort(Constants.PORT);
                config.setResource("myresource");
                config.setDebuggerEnabled(true);
                config.setKeystoreType("AndroidCAStore");
                config.setConnectTimeout(100000);

                try {

                    config.setUsernameAndPassword(getUserName(), password);
                } catch (Exception e) {

                    e.getMessage();
                }
                Constants.connection = new XMPPTCPConnection(config.build()); //new XMPPConnection(Constants.connConfig);
                try {

                    if (!Constants.connection.isConnected()) {
                        Constants.connection.connect();
                    }

                    Log.i("ChatActivity", "Connected to "
                            + Constants.connection.getHost());
                } catch (XMPPException ex) {
                    Log.e("ChatActivity",
                            "Failed to connect to " + Constants.connection.getHost());
                    Log.e("ChatActivity", ex.toString());
                    //  setConnection(null);

                } catch (IOException | SmackException e) {
                    e.printStackTrace();
                    Log.e("my error outer", e.getMessage() + " <- Understand 0 ? !!!");
                }
                try {
                    Log.d("chat : user name", getUserName());
                    try {
                        Log.d("chat : password", AESCrypt.decrypt(Constants.key_store_pair, enc_login_key));

                    } catch (Exception e) {
                        e.printStackTrace();
                    }

                    try {

                        SASLAuthentication.blacklistSASLMechanism("SCRAM-SHA-1");
                        Constants.connection.login(getUserName(), password);
                        Constants.connection.getServiceName();
                        Log.d("service name=", Constants.connection.getServiceName());

                    } catch (Exception e) {
                        e.printStackTrace();
                        Log.e("my error inner", e.getMessage() + " <- Understand 1 ? !!!");
                    }

                    Log.i("ChatActivity", "Logged in as    "
                            + Constants.connection.getUser());

                    Log.i("You are valid user",
                            "your Token is  " + Constants.connection.getUser());


                } catch (Exception ex) {


                }


            }

    });
    t.start();

}

It connected Successfully...

After when I creating New Conference Room at that time i register that conference room by calling following method :

 private MultiUserChat createGroupChat(XMPPConnection connection,String  room_id, String groupName, String registered_beam_iddd) throws XMPPException, SmackException {

    // This code call when creating new conference room

    Constants.mucM = MultiUserChatManager.getInstanceFor(connection); //new MultiUserChatManager(connection, registered_beam_iddd + "@" + groupName);
    Constants.muc = Constants.mucM.getMultiUserChat(registered_beam_iddd + "@" + groupName);

    if(Constants.connection.isConnected())
    {


        if(Constants.connection.isAuthenticated()) {
            Constants.muc.createOrJoin(room_id + "@" + groupName);  //  

            Form form = Constants.muc.getConfigurationForm();
            Form submitForm = form.createAnswerForm();
            Constants.muc.sendConfigurationForm(submitForm);

            Log.d("Room Created : Name : " , room_id + "@" + groupName);
        }
        else
        {
            //Toast.makeText(getActivity(),"Authenicated false",Toast.LENGTH_LONG).show();
            Log.d("ooo", "authentication failed in AddBeam");
        }
    }
    else
    {
        Toast.makeText(getActivity(),"Connection Loss",Toast.LENGTH_LONG).show();
    }
    return Constants.muc;
    //onesecond
}

When I Click on number of conference room ( listview ) , that means when i enter on any of my conference room , i call following method to join room and get history,

  private MultiUserChat joinGroupChat(XMPPConnection connection, String room_id, String groupName, String registered_beam_iddd) throws XMPPException, SmackException {

    // This code called when user enter in Chat-conference room

    if (Constants.connection.isConnected()) {

        if (Constants.muc == null) {
            Constants.mucM = MultiUserChatManager.getInstanceFor(connection); //new MultiUserChatManager(connection, registered_beam_iddd + "@" + groupName);
            Constants.muc = Constants.mucM.getMultiUserChat(registered_beam_iddd + "@" + groupName);
        }
        if (Constants.connection.isAuthenticated()) {

            if (!Constants.muc.isJoined()) {


                DiscussionHistory history = new DiscussionHistory();
                history.setMaxStanzas(20);

                Constants.muc.join(room_id + "@" + groupName, "password", history, Constants.connection.getPacketReplyTimeout());  //  @conference.tubsystems.com  



            } else {
                Log.d("joined: ", room_id + "@" + groupName);
            }
        } else {
            Log.d("ooo", "authentication failed in AddBeam");
        }
    } else {
        Toast.makeText(getApplicationContext(), "Connection Loss", Toast.LENGTH_LONG).show();
        try {

            Constants.connection.connect();
            Log.i("ChatActivity", "Connected to "
                    + Constants.connection.getHost());
        } catch (Exception ex) {
            Log.e("ChatActivity",
                    "Failed to connect to " + Constants.connection.getHost());
            Log.e("ChatActivity", ex.toString());
            //  setConnection(null);
        }
    }
    return Constants.muc;
    //onesecond
}

For Sending Message to conference :

    private void sendmessage(String text, String room) {

    String to = beamId + "@"+groupname;


    Message msg = new Message(to, Message.Type.groupchat);
    msg.setBody(text);
    if (Constants.connection != null) {
        try {
            Constants.connection.sendPacket(msg);
            Log.d("Send to room  : Name : ", to);
        } catch (Exception e) {
            Log.d("ooo", "msg exception" + e.getMessage());
        }

        messages.add(text);
        msg_send_receive_val = 1;

        new setListAdapter().execute();
     }

  }

But it giving Some time connection error , some time 406 or 407 error and when i first time enter in the conference room at that time only it display past history message and then automatically removed, and message also not sending some times and some times sending , i dont know what is problem , while sending message it giving 406-407 modify- not acceptable error and some times giving other error.

I don't know but anything missing in above code , or anything other required to configure conference room ? Please help me as much fast as possible.

Thanks in advance.

Joseph Mekwan
  • 1,082
  • 1
  • 15
  • 28

0 Answers0