Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / November 2005

Tip: Looking for answers? Try searching our database.

How to read byte array on sockets?

Thread view: 
ami - 04 Nov 2005 18:42 GMT
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,


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.