I'm dealing with UDP and sending some messages. One message contains binary XML and I'm using KXML2 with the following code. It runs fine. On UDP, I have to take a fixed buffer at the DatagramPacket. Using this byte array taken from the DatagramPacket and run my KXML2 functions fires everytime an "Unexpected EOF" exception.
myPacket = new DatagramPacket( new byte[1024], 1024);
InputStream in = new ByteArrayInputStream(myPacket.getData());
WbxmlParser parser = new WbxmlParser();
parser.setInput(in, "UTF-8");
org.kxml2.kdom.Document dom = new org.kxml2.kdom.Document();
dom.parse(parser);
The exception is thrown at 'dom.parse(parser);' Any idea, how a correct EOF looks like? Maybe it is possible, to place the size of the binary xml blob at the start of the package and extract the data, but this is just a second way for me.
InputStream in = new ByteArrayInputStream(myPacket.getData());
You're ignoring the actual length of the packet. It should be:
InputStream in = new ByteArrayInputStream(myPacket.getData(), myPacket.getOffset(), myPacket.getLength());
but I fear that either you haven't transmitted the entire data or the byte array you construct the receiving DatagramPacket with is too short.