On Wed, Jul 24, 2013 at 8:22 AM, Lotte R. Leben <lo...@zombietetris.de>wrote:

>
> *But* As far as I know readDelimited() only works with inputStreams, which
> kind of contradicts the whole UDP thing.
> Since adding the delimiter was a tad tricky, I wasn't confident that the
> following would work:
>
> - add delimiter in python as mentioned above
> - receive datagram in java
> - read first bit to know length = n
> - read next n bytes
> - PacketMessage.parseFrom(chunkOfnBytes)
>

Should be fine. May be simplest to wrap your bytearray in a
CodedInputStream directly via CodedInputStream.newInstance().
But see below - if the contents of the UDP datagram is entirely message
data you shouldn't need a separate length at all.

Or if there is no other data in the UDP datagram you could just use the
>> datagram length directly (i.e. get rid of the trailing garbage - why are
>> you padding the datagram in the first place?)
>>
>>
> We are not padding it on purpose and I'd love to know how or why that
> garbage data got in there. :(
>

If you are using DatagramSocket.receive(DatagramPacket) this probably means
you are not looking at packet.getLength() on return. The datagram received
is read into the array owned by DatagramPacket, but it may not fill the
entire array so you need to inspect and use the actual length returned
rather than using the whole array. You want something approximately like
this:

  DatagramPacket p = new DatagramPacket(new byte[MAX_DATAGRAM_SIZE],
MAX_DATAGRAM_SIZE);
  socket.receive(p);
  PacketMessage message =
PacketMessage.parseFrom(CodedInputStream.newInstance(p.getData(),
p.getOffset(), p.getLength()));

If that's not the problem, then I would look at the datagram on the wire
(via e.g. wireshark) to see if the garbage is present there - that'd narrow
it down to sender or receiver at least.

Oliver

-- 
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to protobuf+unsubscr...@googlegroups.com.
To post to this group, send email to protobuf@googlegroups.com.
Visit this group at http://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to