谁能告诉这段代码有什么问题,我所做的是
- 客户端从 c++ 发送图像数据,它是 uchar 数组。
- Java 服务器使用服务器套接字接收此数据并存储为字节数组。
这是代码...
private ServerSocket serverSocket;
InputStream in;
int imageSize=300;//921600;//expected image size 640X480X3
public imageReciver(int port) throws IOException {
serverSocket = new ServerSocket(port);
}
Socket server = null;
server = serverSocket.accept();
in = server.getInputStream();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte buffer[] = new byte[100];
int remainingBytes = imageSize; //
while (remainingBytes > 0) {
int bytesRead = in.read(buffer);
if (bytesRead < 0) {
throw new IOException("Unexpected end of data");
}
baos.write(buffer, 0, bytesRead);
remainingBytes -= bytesRead;
}
in.close();
byte imageByte[] = new byte[imageSize];
imageByte = baos.toByteArray();
baos.close();
在阅读时,inputstream in
我对buffer
.