Screenshot of remote computer
<p>Hello I was doing a program of taking a snapshot of remote computer.</p>

<p>I have done up to.</p>

<p><strong>ScreenServer.java.</strong></p>

<pre><code>import java.net.*;
import java.awt.*;
import java.awt.image.*;
import java.io.*;
import javax.imageio.ImageIO;

public class ScreenServer {
    public static void main(String[] args) throws Exception {
        Robot robot = new Robot();
        BufferedImage screen;

        while (true) {
            ServerSocket server = new ServerSocket(6659);
            Socket client = server.accept();

            Rectangle size = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
            screen = robot.createScreenCapture(size);
            int[] rgbData = new int[(int) (size.getWidth()*size.getHeight())];
            screen.getRGB(0,0, (int) size.getWidth(), (int) size.getHeight(), rgbData, 0, (int) size.getWidth());

            OutputStream baseOut = client.getOutputStream();
            ObjectOutputStream out = new ObjectOutputStream(baseOut);

            ImageIO.write(screen, "png", new File("d:\\orig_screen.png"));
            out.writeObject(size);

            for (int x = 0; x &lt; rgbData.length; x++) {
                out.writeInt(rgbData[x]);
            }

            out.flush();
            server.close();
            client.close();
            out.close();
            baseOut.close();
        }
    }
}
</code></pre>

<p><strong>ScreenClient.java</strong></p>

<pre><code>import java.net.*;
import java.awt.*;
import java.awt.image.*;
import java.io.*;
import javax.imageio.ImageIO;

public class ScreenClient {

    public static void main(String[] args) throws Exception {
        Socket server = new Socket("172.22.6.50",6659);

        ObjectInputStream in = new ObjectInputStream(server.getInputStream());

        Rectangle size = (Rectangle) in.readObject();

        int[] rgbData = new int[(int)(size.getWidth() * size.getHeight())];

        for (int x = 0; x &lt; rgbData.length;x++) {
            rgbData[x] = in.readInt();
        }

        in.close();
        server.close();

        BufferedImage screen = new BufferedImage((int) size.getWidth(), (int) size.getHeight(), BufferedImage.TYPE_INT_ARGB);

        screen.setRGB(0,0, (int) size.getWidth(), (int) size.getHeight(), rgbData, 0,(int)size.getWidth());

        ImageIO.write(screen, "png", new File("d:\\screen.png"));
    }
}
</code></pre>

<p>But it's not working properly.  The server takes it's own snapshot.  Please provide a solution.</p>
