I am trying to make a server-client model in which the server can see what the client is doing on their systems. I want to capture and send an image via a socket (skt). How can I display the image received by the server.
Client Thread:
screenShot = new Robot().createScreenCapture(new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()));
ImageIO.write(screenShot, "PNG", skt.getOutputStream());
Server Thread:
BufferedImage image = ImageIO.read(connarray.get(0).getInputStream());
Graphics g = image.getGraphics();
g.drawImage(image, 500, 500, null);
You don’t ask an actual question here, but I could make a couple of observations.
Both your client and server code is catching and squashing exceptions. If any exceptions were thrown by the client or server-side, your code is throwing away all of the evidence. Change
to
If there are exceptions being thrown, this will tell you what they are. (In production code, you should probably log exceptions instead of calling
printStackTrace(...)… but that is a lesson for later.)Taking a screenshot every 1/10th of a second is going to generate a lot of load on the client and server side.
There are existing (non-Java) tools for doing this kind of thing.