look i changed my code for this and i'll let you see what the exactly happened...
Server Java Side :
/during the connecting
private void whileConnecting() throws IOException, AWTException, InterruptedException {
int i=0;
while(i<5){
System.out.println("i = " + i);
capture = robot.createScreenCapture(screenRectangle);
baos = new ByteArrayOutputStream();
ImageIO.write(capture, "png", baos);
baos.flush();
System.out.println("Size of baos = " + baos.size());
byte[] buffer = baos.toByteArray();
baos.close();
baos = null;
output.writeObject(buffer);
output.flush();
i++;
Thread.sleep(1000);
}
}
Client Android Side :
try {
connection = new Socket(getIntent().getStringExtra("ip"), 8080);
input = new ObjectInputStream(connection.getInputStream());
int i = 0;
while (i < 5) {
i++;
buffer = (byte[]) input.readObject();
Toast.makeText(getApplicationContext(), "buffer length = " + buffer.length, Toast.LENGTH_LONG).show();
screenCapture.setImageBitmap(BitmapFactory.decodeByteArray(buffer, 0, buffer.length));
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally {
try {
connection.close();
} catch (IOException e) {
Toast.makeText(getApplicationContext(), "Error with closing connection", Toast.LENGTH_LONG).show();
}
}
i receive on the phone only one picture i dont know how to upload it here
but that what i receive :
i = 0
Size of baos = 81559
i = 1
Size of baos = 81556
i = 2
Size of baos = 109330
i = 3
Size of baos = 110072
and that exactly the length of the bytes that i sent it ...!!