[英]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. 我需要从包含80个4字节int字段的服务器接收320字节的数据。 How do I receive them in bytes of 4 and display their respective int values?
我如何以4字节为单位接收它们并显示它们各自的int值? 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);
for (int i = 0; i < 80; i++) {
System.out.println(datainput.readInt());
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.