简体   繁体   English

如何接收从服务器发送的字节数组并一次读取4个单字节

[英]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.

相关问题 是否可以在服务器上解码从客户端作为字节数组发送的字节? - Is it possible to decode bytes on a server which were sent from a client as a byte array? 从应用程序发送的字节未在服务器上正确读取 - Bytes sent from app are not read properly on server 我如何使用 OkHttp 接收服务器响应发送的 cookie? - How do i receive the cookies sent in response by the server using OkHttp? 如何从InputStream读取字节? - How do I read bytes from InputStream? 如何从字节数组(2字节/像素)获取PNG? - How can I get a PNG from a byte Array (2 bytes/pixel)? 如何一次读取文件x字节? 在java中 - How do I read file x bytes at a time ? in java 将文件转换为字节数组并使用UDP传输。 如何从这个字节数组获取服务器上的文件名? - Converting file to byte array and transmitting it with UDP. How to get file name on server from this array of bytes? 如何将所有字节发送到单个数组中,然后再在字节之间进行异或运算? - How to send all byte into single array and later xor between the bytes? 如何从服务器中的字节数组中的文件中读取数据 - How to read data from file in server in byte array 如何在 Eclipse Java 调试器中将字节数组显示为十六进制字节或无符号十进制数的数组? - How do I display a byte array as an array of hex bytes or unsigned decimal numbers in the Eclipse Java debugger?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM