I want to connect openfire with samck API and then chat with another user. For that i created user in openfire. And i can login to them from the code below. But i cannot add two user as friends.
I ran this code twice for different user in different pc and also in same pc.
I added them as friend by logging on openfire sever. I did it manually. so the code shows the buddy list. But cant send any message to the budies.
i found this code from here
[link]http://www.javaprogrammingforums.com/java-code-snippets-tutorials/551-how-write-simple-xmpp-jabber-client-using-smack-api.html[/link]
When i send message to one of the buddy from another buddy it sends successfully but then receive error message in smack debugging window.
This is the error message :
<message id="LM8uW-5" to="nayim@sust-2a24ea2754/Smack" from="admin@example.com" type="error"> <thread>DA50z0</thread> <error code="404" type="CANCEL"> <remote-server-not-found xmlns="urn:ietf:paramsml:nsmpp-stanzas"/> </error> </message>
This is the java code to connect smack and openfire :
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; public class runjabber implements MessageListener{ XMPPConnection connection; public void login(String userName, String password) throws XMPPException { ConnectionConfiguration config = new ConnectionConfiguration("127.0.0.1", 5222,"localhost"); connection = new XMPPConnection(config); connection.connect(); connection.login(userName, password); } public void sendMessage(String message, String to) throws XMPPException { Chat chat = connection.getChatManager().createChat(to, this); chat.sendMessage(message); } public void displayBuddyList() { Roster roster = connection.getRoster(); Collection<RosterEntry> entries = roster.getEntries(); System.out.println("\n\n" + entries.size() + " buddy(ies):"); for(RosterEntry r:entries) { System.out.println(r.getUser()); } } public void disconnect() { connection.disconnect(); } public void processMessage(Chat chat, Message message) { if(message.getType() == Message.Type.chat) System.out.println(chat.getParticipant() + " says: " + message.getBody()); } public static void main(String args[]) throws XMPPException, IOException { // declare variables runjabber c = new runjabber(); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String msg; // turn on the enhanced debugger XMPPConnection.DEBUG_ENABLED = true; // Enter your login information here c.login("admin", "admin"); c.displayBuddyList(); System.out.println("-----"); System.out.println("Who do you want to talk to? - Type contacts full email address:"); String talkTo = br.readLine(); System.out.println("-----"); System.out.println("All messages will be sent to " + talkTo); System.out.println("Enter your message in the console:"); System.out.println("-----\n"); while( !(msg=br.readLine()).equals("bye")) { c.sendMessage(msg, talkTo); } c.disconnect(); System.exit(0); } }
I really need to solve this problem. So if anyone can help it would be very helpful to me. Thank you.