Screenshot of remote computer
Hello I was doing a program of taking a snapshot of remote computer.
I have done up to.
ScreenServer.java.
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 < rgbData.length; x++) {
out.writeInt(rgbData[x]);
}
out.flush();
server.close();
client.close();
out.close();
baseOut.close();
}
}
}
ScreenClient.java
import java.net.*;
import java.awt.*;
import java.awt.image.*;
import java.io.*;
import javax.imageio.ImageIO;
public class Screen开发者_运维百科Client {
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 < 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"));
}
}
But it's not working properly. The server takes it's own snapshot. Please provide a solution.
You are capturing the server's screen shot. see here for help.
The server takes it's own snapshot...
Well, obviously it can't take a snapshot of the screen of some other random computer. It would be a massive security hole if it could do that!!
If you want to take a snapshot of a computer's screen, you have to do it from a program executing on that computer, or via some remote desktop protocol. In other words, the computer has to be set up / configured to allow this to happen.
I think your problem is that you are simply misunderstanding the way those two programs are intended to be used. You are supposed to run the ScreenServer
app on the machine whose screen you want to snapshot and the ScreenClient
app on the machine where you want to view the snapshot.
You should also be aware that if you run the ScreenServer
app on a machine, any other computer on the network can capture its screen. This is very insecure.
精彩评论