发送XMPP(短信)消息 [英] Send XMPP (Smack) Message
问题描述
好吧,这个问题应该很简单,但是我不能弄清它的深处.
Ok, the problem should be trivial but I can't get to the bottom of it.
我有两个用户A& B
I have two users A & B
此示例的JID是A @ 123和B @ 123,其中123是服务器的IP.
Their JID's for this example will be A@123 and B@123 where 123 is the IP of the server.
我正在使用以下代码从A-> B发送消息:
I'm sending a message from A->B using the following code:
chat = chatmanager.createChat(username,
new MessageListener() {
public void processMessage(Chat chat, Message message) {}});
String sendUsername = username + "@123";
Message msgObj = new Message(sendUsername, Message.Type.chat);
msgObj.setBody(message);
chat.sendMessage(msgObj);
我已经对IP进行了硬编码,以便100%确保在昵称的末尾附加"@ 123",这样就不会有不正确的JID.
I've hardcoded the IP so that I'm 100% sure that I attach the "@123" at the end of the nickname so there are no incorrect JIDs.
因此,A @ 123将msgObj发送到B @ 123.这就是我理解XMPP消息传递工作的方式.无法从A-> B发送,但必须是A @ 123-> B @ 123.
So A@123 sends msgObj to B@123. This is how I understood XMPP messaging to work. That you can't send from A->B but it must be A@123 -> B@123.
但是,我的服务器似乎不这么认为.它不断通知我以下错误:
However, my server seems to think otherwise. It continuously informs me of the following error:
2010.12.27 19:02:52 [org.jivesoftware.openfire.session.LocalOutgoingServerSession
.createOutgoingSession(LocalOutgoingServerSession.java:258)] Error trying to
connect to remote server: A(DNS lookup: A:5269)
java.net.UnknownHostException: A
在Openfire服务器上的A和B的花名册中,他们彼此之间都是具有适当JID(username @ 123)的联系人.
In both A and B's roster on the Openfire server, they have each other as a contact with the proper JIDs (username@123).
谁能提供一些见识?我迷路了.
Can anyone provide some insight? I'm lost.
修改
我正在尝试使用Wireshark捕获发送到Openfire服务器和从Openfire服务器发送的XML,以确定消息的接收者是否正确命名(A @ 123而不是A).
I'm trying to use Wireshark to catch the XML sent to and from the Openfire server to determine if the recipient of the message is named properly (A@123 instead of A).
在使用Wireshark时,由于XML的传输,我收到了这个消息:
Upon using Wireshark, I received this as the XML being transferred:
\302\3469\223\341\3429\000\000\000\000\377\377
我已禁用SSL,但连接不安全.我不确定为什么要获取SSL类型的XML,是这样的吗?
I have disabled SSL, I have connected un-securely. I'm not sure why I'm getting SSL type XML, is that what it is?
推荐答案
原来这个问题的答案只是被忽略了.
Turns out the answer to this problem was something that was just overlooked.
在第一行代码中:
chat = chatmanager.createChat(username, new MessageListener() {
public void processMessage(Chat chat, Message message) {}
});
我没有使变量"username"具有正确的IP扩展名.所以它只是"A"而不是"A @ 123"
I didn't make the variable "username" have the proper IP extension. So it was merely "A" instead of "A@123"
将"sendUsername"移到顶部,将"username"更改为"sendUsername"使一切正常:)
Moving "sendUsername" to the top and Changing "username" to "sendUsername" makes everything work great :)
愚蠢的错误.
这篇关于发送XMPP(短信)消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!