![](/img/trans.png)
[英]Is it possible to decode bytes on a server which were sent from a client as a byte array?
[英]How do I receive byte array sent from a server and read 4 single bytes at a time
我需要從包含80個4字節int字段的服務器接收320字節的數據。 我如何以4字節為單位接收它們並顯示它們各自的int值? 謝謝。
不確定這是否適合接收部分:
//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.