Cannot send message to openfire server

末鹿安然 提交于 2019-12-11 02:22:23

问题


I am unable to send a message to a XMPP client on an openfire server using SMACK API. I m not sure where i am going wrong. I tested the same code on gtalk and it works fine.

public class SenderTest 
{
public static void main(String args[])
{
    ConnectionConfiguration connConfig = new ConnectionConfiguration("localhost", 5222);
        connConfig.setSASLAuthenticationEnabled(false);
       XMPPConnection connection = new XMPPConnection(connConfig);

        try {
            connection.connect();
            System.out.println("Connected to " + connection.getHost());
        } catch (XMPPException ex) {
            //ex.printStackTrace();
            System.out.println("Failed to connect to " + connection.getHost());
            System.exit(1);
        }
        try {
            connection.login("sender", "a");
            System.out.println("Logged in as " + connection.getUser());

            Presence presence = new Presence(Presence.Type.available);
            connection.sendPacket(presence);

        } catch (XMPPException ex) {
            //ex.printStackTrace();
            System.out.println("Failed to log in as " + connection.getUser());
            System.exit(1);
        }

    ChatManager chatmanager = connection.getChatManager();
    Chat newChat = chatmanager.createChat("receiver@example.com", new MessageListener() {
        public void processMessage(Chat chat, Message message) {
            System.out.println("Received message: " + message);
        }
    });

    try {
        newChat.sendMessage("Howdy!");
        System.out.println("Message Sent...");
    }
    catch (XMPPException e) {
        System.out.println("Error Delivering block");
    }
}

}

It gives me a 'Message Sent...'. but no message arrives at the receiving end.

Also if 'sender' wants to send a message to 'receiver' then does it mean that they should be added to each other's 'roster'


回答1:


You are logging in to localhost, but you are sending a message to receiver@example.com. Are you sure that is the correct jid for the other user? I would expect that it is receiver@localhost.

AFAIK, chatting does not require that they are on each others rosters, although that is the more typical case.




回答2:


You check the error log of openfire server. You might get the error like 'incorrect hostname in stream header. Host: example.com' I have seen such type of error, if your server name is 'localhost' , then you can send messages between users like user1@localhost.com , user2@localhost.com ...etc

but user1@localhost.com can't send message to xyz@example.com.



来源:https://stackoverflow.com/questions/9784320/cannot-send-message-to-openfire-server

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!