我試圖發送消息。與firebase xmpp服務器連接完成。我正在使用最新的smack 4.2。java - 使用smack4.2發送消息錯誤firebase xmpp
public myClient(String senderId, String serverKey) throws IOException, NotConnectedException, InterruptedException {
Roster.setRosterLoadedAtLoginDefault(false);
Jid jid ;
jid = JidCreate.from(HOST);
final XMPPTCPConnectionConfiguration conf = XMPPTCPConnectionConfiguration.builder()
.setCompressionEnabled(false)
.setSendPresence(false)
.setConnectTimeout(10000)
.setHost(HOST)
.setDebuggerEnabled(false)
.setPort(PORT)
.setXmppDomain((DomainBareJid) jid)
.setSocketFactory(SSLSocketFactory.getDefault())
.setUsernameAndPassword(senderId + "@gcm.googleapis.com", serverKey)
.build();
this.conn = new MyXMPPTCPConnection(conf);
try {
conn.connect();
conn.login();
} catch (XMPPException | InterruptedException | SmackException e) {
throw new IOException(e);
}
Roster roster = Roster.getInstanceFor(conn);
Collection<RosterEntry> entries = roster.getEntries();
for (RosterEntry entry : entries) {
System.out.println(entry);
}
Entity jEntity ;
Jid jid1 = JidCreate.from("text");
EntityBareJid jid21 = JidCreate.entityBareFrom("[email protected]");
Chat chat = ChatManager.getInstanceFor(conn)
.createChat(jid21);
Message newMessage = new Message();
String t = "hello this is a test message";
newMessage.setBody(t.toString());
/* ((Object) chat).send(newMessage);*/
chat.sendMessage(newMessage);
StanzaFilter filter = new AndFilter(new StanzaTypeFilter(Message.class));
//PacketCollector myCollector = conn2.createPacketCollector(filter);
// Normally, you'd do something with the collector, like wait for new packets.
StanzaListener myListener = new StanzaListener() {
@Override
public void processPacket(Stanza packet) throws SmackException.NotConnectedException {
System.out.println("packet = [" + packet + "]");
}
};
conn.addAsyncStanzaListener(myListener, filter);
while (true) {
}
//conn2.disconnect();
}
當我運行這種方法得到了以下錯誤
包= [你好 這是一個測試 message25667738-6dd1-4c74-a64b-2fdbac74339bInvalidJson: MissingPayload] 07月26 2017 12:52:46 PM
org.jivesoftware.smack.tcp.XMPPTCPConnection $ PacketReader parsePackets INFO:MyXMPPTCPConnection [[email protected]/41CA77 F0] (0)收到結束元素。服務器想要終止 連接,調用disconnect()
請檢查並建議。 在此先感謝。
[GCM無效JSON丟失負載]的可能重複(https://stackoverflow.com/questions/30393534/gcm-invalid-json-missing-payload) – Antoniossss