Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: problem chatting with smack api with openfire server

  1. #1
    Junior Member
    Join Date
    Jun 2010
    Posts
    8
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default problem chatting with smack api with openfire server

    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.
    Last edited by calicratis19; July 16th, 2010 at 01:08 AM.


  2. #2
    Junior Member
    Join Date
    Jun 2010
    Posts
    8
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: problem chatting with smack api with openfire server

    No one to help me I need help

  3. #3
    Junior Member
    Join Date
    Nov 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: problem chatting with smack api with openfire server

    Quote Originally Posted by calicratis19 View Post
    No one to help me I need help
    Hi,

    Did you got the solution. I am also facing the same issue but could not able to fix it.

    Any help is highly appreciated.

    Thanks

Similar Threads

  1. How to Write a simple XMPP (Jabber) client using the Smack API
    By JavaPF in forum Java Networking Tutorials
    Replies: 35
    Last Post: August 5th, 2014, 01:59 AM
  2. UDP Server Client program to send and receive messages
    By Koren3 in forum Java Networking
    Replies: 1
    Last Post: September 5th, 2011, 11:16 AM
  3. Java chatting program implementing socket logic
    By sivakrishna.g in forum Java Networking
    Replies: 2
    Last Post: October 20th, 2009, 01:47 AM
  4. Replies: 2
    Last Post: July 7th, 2009, 03:34 PM
  5. [SOLVED] Problem in UDS client,server program
    By Koren3 in forum Java Networking
    Replies: 8
    Last Post: March 28th, 2009, 04:05 PM

Tags for this Thread