How do I recieve byteArray send from Server and read 4 single bytes at a time.

Posted by k80sg on Stack Overflow See other posts from Stack Overflow or by k80sg
Published on 2010-03-21T10:21:05Z Indexed on 2010/03/21 10:31 UTC
Read the original article Hit count: 347

Filed under:

I need to receive 320 bytes of data from a server which consist of 80 4 bytes int fields. How do I receive them in bytes of 4 and display their respective int values? Thanks. Not sure if this is right for the receiving part:

//for reading the data from the socket 

BufferedInputStream bufferinput=new BufferedInputStream(NewSocket.getInputStream());

DataInputStream datainput=new DataInputStream(bufferinput);

byte[] handsize=new byte[32];

// The control will halt at the below statement till all the 32 bytes are not read from the socket.  

datainput.readFully(handsize); 

© Stack Overflow or respective owner

Related posts about java