Hello,
I have problem while reading array of bytes. I have sent
array of bytes over the socket using DataOutputStream. Here is the code
for that:
byte[] ethFrame;
out.write(ethFrame, 0, ethFrame.length);
And tried to read on the other end with
in.read(bytes,offset, length);
or
in.readFully(bytes,offset, length);
but I could not print it out?
Can any one help me to read byte array ?
Please help me!!
zero - 04 Nov 2005 20:18 GMT
"ami" <amruta@hotmail.com> wrote in news:1131126151.309518.210630
@g14g2000cwa.googlegroups.com:
> Hello,
>
[quoted text clipped - 16 lines]
>
> Please help me!!
in.read should work.
byte[] bytes = new byte[100];
in.read(bytes, 0, b.length);
for(byte b : bytes)
Sytem.out.print(b + " ");
Matt Humphrey - 05 Nov 2005 02:17 GMT
> Hello,
>
[quoted text clipped - 14 lines]
>
> Can any one help me to read byte array ?
You'll have to give us more to go on. In what way does it not work? What
are the values for bytes, offset and length? How does the reader know how
many bytes to read--TCP is stream (not packet) oriented and you don't
necessarily receive the data in the same blocks in which you sent it. Show
your real code or produce a short program that demonstrates the problem. (My
off-the-cuff guess is that you're writing (for example) 80 bytes or whatever
ethFrame.length turns out to be, but your read buffer is 100 bytes and
you're waiting for it to fill up, which it never will. You must know the
length in advance or have some way of knowing when to stop reading.
Cheers,