java - Problem adding buddy with smack api and openfire server -


Hello I'm new in Java and it is giving me a lot of stress I need to talk to Taste API and Open Fire Server I have my Java code below for this

  import java.util *; Import java.io * *; Import org.jivesoftware.smack.Chat; Import org.jivesoftware.smack.ConnectionConfiguration; Import org.jivesoftware.smack.MessageListener; Import org.jivesoftware.smack.Roster; Import org.jivesoftware.smack.RosterEntry; Import org.jivesoftware.smack.XMPPConnection; Import org.jivesoftware.smack.XMPPException; Import org.jivesoftware.smack.packet.Message; PublicJen RunJabberSmackAPI implements MessageListener {XMPP connection connection; Public Zero Login (string username, string password) throws XMPPException {connection configuration config = new connection configuration ("127.0.0.1", 5222, "localhost"); Connection = new XMPPConnection (config); Connection.connect (); Connection.login (username, password); } Public Zero send message (string message, string to) throws XMPPException {chat chat = connection.getChatManager (). CreateChat (to, this); Chat.sendMessage (message); } Public Zero Performance BuddyList () {roster roster = connection.getRoster (); Collections & lt; RosterEntry & gt; Entries = roster. Gatekeeper (); System.out.println ("\ n \ n" + Entries. Size (+) "Friend (ies):"); (For Roster Entry R: Entries) {System.out.println (r.getUser ()); }} Public Disconnect Disk () {connection.disconnect (); } Public zero process messages (chat chats, message messages) {if (message.getType () == Message.Type.chat) System.out.println (chat.getParticipant () + "says:" + message.getBody ( )); } Public static zero master throws XMPPException, IOException {// declared variable variablesSmackAPI c = new RunJabberSmackAPI (); Buffer reader br = new buffed reader (new inputstreamer (system.)); String msg; // Enhanced debugger XMPPConnection.DEBUG_ENABLED = true; // Enter your login information here c.login ("admin", "admin"); // I created this user with Open Fire c.displayBuddyList (); Println ("-----"); System.out.println ("Who do you want to talk to? - Type the full email address to contacts:"); String talk to = br.readLine (); Println ("-----"); System.out.println ("All messages will be sent to" + talkTo "); System.out.println (" Enter your message in the console: "); Println (" ----- \ n "); Whereas (! (Msg = br.readline ()). Equals ("bye") {c.SendMessage (msg, talkTo);} C.disconnect (); System.exit (0);}}  

I run this code twice in my pc. For individual user I added these two users as a friend openly in the form of a friend but when they logged Java code upwards If they do, they are available But they can not send their presence to each other, instead they receive two error messages from their friend.

  First error message: www.freeimagehosting Net / image.php? Eac15f606a.jpg second error message: www.freeimagehosting.net/image.php?b827058d07.jpg  

I do not know what is wrong in my code and actually make me I will have to solve this problem soon. I posted this problem on other forums as well. But no answer was found. So if any one can solve it then this is a great help. Thanks.

In many threads in the web of IgniteReautime, you can see that you need to get Skak to regain asynchronous roster Required, so either you change the displayBuddyList () to use the RosterListener instead, or you use the thread (5000) between the login and the displaybirdlist () function (if you do not use a listener Want to do it, which is recommended) updated press Take some time to pop the roster with the rays.


Comments