简体   繁体   中英

Smack: Message triggering "not-well-formed" exception

I am trying to send a string with the following format as a message through Smack:

<STX>1<US>fileID<US>fileName<US>fileSize<US>senderID<US>stringEncodedByteArray<ETX>

I am generating the parameters like so:

String stringEncodedByteArray = Base64.getEncoder().encodeToString(bytes);
String fileID = java.util.UUID.randomUUID().toString();
String STX = Character.toString((char) 2);
String ETX = Character.toString((char) 3);
String US = Character.toString((char) 31);
String fileName = "file1";
String fileSize = "1000";
String senderID = "user1";

Now, when I am trying to send this message I receive the following error:

org.jivesoftware.smack.AbstractXMPPConnection callConnectionClosedOnErrorListener WARNING: Connection XMPPTCPConnection[hemodd2@192.168.123.242/88381984845654635827858] (0) closed with error org.jivesoftware.smack.XMPPException$StreamErrorException: not-well-formed You can read more about the meaning of this stream error at http://xmpp.org/rfcs/rfc6120.html#streams-error-conditions not well-formed (invalid token)

It seems that the message format is causing a conflict with the inner workings of Smack as I can send normal messages such as "Hello World" without any issues. I know that I need to reformat the message but I can't figure out how I should go about it. I have read the linked page in error description but still don't understand the exact issue. Any help is appreciated.

That's is not Smack telling you that the message is not well formed, but the XMPP server. This is likely causes by the usage of ASCII control characters which are not allowed in XML 1.0.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM