Can anyone tell what wrong with this code, what I done is that
- Client send image data which is uchar array from c++.
- Java server receives this data using server socket and store as byte array.
Here is the code...
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();
While reading from inputstream in
I am getting negative value on buffer
.