我有一个要发送到服务器的byte[]
数组,是byte[][]
我在客户端中有此代码
DataOutputStream imgWriter = new DataOutputStream(new BufferedOutputStream(socket.getOutputStream()));
imgWriter.writeInt(images.length);
for(int i=0;i<imagenes.length;i++){
imgWriter.writeInt(images[i].length);
imgWriter.write(images[i]);
imgWriter.flush();
}
imgWriter.close();
服务器中的此代码
DataInputStream datInput = new DataInputStream(new BufferedInputStream(socket.getInputStream()));
int numImgs = datInput.readInt(); //img num
byte[][] imagenes = new byte[numImgs][];
for(int i=0;i<numImgs;i++){
int length = datInput.readInt();
imagenes[i] = new byte[length];
datInput.read(imagenes[i], 0, length);
}
我在服务器中正确接收了第一个byteArray,但是在第二个线程中,该行阻塞了:
int numImgs = datInput.readInt(); //img num
并在相同的客户端中,正确发送第一个byteArray但在该行中阻塞:
imgWriter.writeInt(images.length);
我在做什么不好?