DatagramChannel.read omitting zeros at end of packets?

S

Sebastian Staudt

Hello.

I'm trying to read packets from a DatagramChannel and only get non-
zero data of a packet. Zeros at the end of the packet are discarded.
Doing the same with the channel's DatagramSocket.receive(), I get the
whole packet data.
For example there's a 20 byte long packet arriving which consists of
10 bytes random data and 10 zeros. With the channel I only get the
first 10 bytes. The socket gives me the whole 20 bytes.

Did I miss something or is this a bug in DatagramChannel.read() or
even wanted behavior?

PS: I'm using this with Java 1.5.
 
S

Sebastian Staudt

Oops... I forgot to mention that my "zeros" are a String of multiple
zeros (0x30) terminated by 0x00.
 
S

Sebastian Staudt

Ok... I got it.

After sending over the channel, I did not reset the buffer to a
sufficient size.
So it was merely a coincidence that the additional zeros where cut
off.

Shame on me. ;)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,736
Latest member
zacharyharris

Latest Threads

Top