开发者

How do I receive byte array sent from a server and read 4 single bytes at a time

I need to receive 320 bytes of data from a server which consist of 80 4 byte 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); 开发者_StackOverflow


for (int i = 0; i < 80; i++) {
    System.out.println(datainput.readInt());
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜