tcp - Android How to Configure XMPP Conference - Chat room -
i developing 1 chat application , not work properly, giving different-differet error 406 or 407 , please advice me following code 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 " + constants.connection.gethost()); } catch (xmppexception ex) { log.e("chatactivity", "failed connect " + 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 " + constants.connection.getuser()); log.i("you valid user", "your token " + constants.connection.getuser()); } catch (exception ex) { } } }); t.start(); }
it connected successfully...
after when creating new conference room @ time register conference room calling following method :
private multiuserchat creategroupchat(xmppconnection connection,string room_id, string groupname, string registered_beam_iddd) throws xmppexception, smackexception { // 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 click on number of conference room ( listview ) , means when enter on of conference room , call following method join room , history,
private multiuserchat joingroupchat(xmppconnection connection, string room_id, string groupname, string registered_beam_iddd) throws xmppexception, smackexception { // 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 " + constants.connection.gethost()); } catch (exception ex) { log.e("chatactivity", "failed connect " + constants.connection.gethost()); log.e("chatactivity", ex.tostring()); // setconnection(null); } } return constants.muc; //onesecond }
for sending message conference :
private void sendmessage(string text, string room) { string = 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 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 giving time connection error , time 406 or 407 error , when first time enter in conference room @ time display past history message , automatically removed, , message not sending times , times sending , dont know problem , while sending message giving 406-407 modify- not acceptable error , times giving other error.
i don't know missing in above code , or other required configure conference room ? please me fast possible.
thanks in advance.
Comments
Post a Comment