欢迎来到天天文库
浏览记录
ID:38275118
大小:49.72 KB
页数:8页
时间:2019-06-07
《socket流程+实现桌面监控+通信+zip压缩解压》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、1socket的通信方式、流程2思想A.建立SOCKET连接。B.读取桌面操作情况C.生成图片,并写出。3具体实现packageTCP;importcom.sun.image.codec.jpeg.JPEGCodec;importjava.awt.Dimension;importjava.awt.Image;importjava.awt.Rectangle;importjava.awt.Robot;importjava.awt.Toolkit;importjava.awt.image.BufferedImage;importjava
2、.io.FileOutputStream;importjava.io.IOException;importjava.net.ServerSocket;importjava.net.Socket;importjava.util.zip.ZipEntry;importjava.util.zip.ZipOutputStream;publicclassShellServerextendsThread{privateDimensionscreenSize;privateRectanglerectangle;privateRobotrobot;
3、privateServerSocketserver=null;publicShellServer(){screenSize=Toolkit.getDefaultToolkit().getScreenSize();rectangle=newRectangle(screenSize);//可以指定捕获屏幕区域try{server=newServerSocket(5000);robot=newRobot();}catch(Exceptione){e.printStackTrace();System.out.println(e);}}pub
4、licvoidrun(){ZipOutputStreamos=null;ZipOutputStreamzos=null;Socketsocket=null;while(true){try{socket=server.accept();//socket=newSocket("192.168.1.52",5000);//连接远程IPBufferedImageimage=robot.createScreenCapture(rectangle);//捕获制定屏幕矩形区域os=newZipOutputStream(socket.getOutp
5、utStream());//加入压缩流Imagei=null;os.setLevel(9);os.putNextEntry(newZipEntry("test.jpg"));JPEGCodec.createJPEGEncoder(os).encode(image);//图像编码成JPEGzos=newZipOutputStream(newFileOutputStream("C:/1.zip"));zos.putNextEntry(newZipEntry("test.jpg"));JPEGCodec.createJPEGEncoder
6、(zos).encode(image);//图像编码成JPEGzos.close();System.out.println();os.close();Thread.sleep(500);//每秒20帧}catch(Exceptione){e.printStackTrace();}finally{if(os!=null){try{os.close();}catch(Exceptionioe){}}if(socket!=null){try{socket.close();}catch(IOExceptione){}}}}}publicst
7、aticvoidmain(String[]args){newShellServer().start();}}packageTCP;importjava.awt.*;importjava.awt.image.BufferedImage;importjavax.imageio.ImageIO;importjavax.swing.*;importjava.io.*;importjava.net.ServerSocket;importjava.net.Socket;importjava.util.zip.ZipInputStream;pub
8、licclassShellClientextendsJFrame{privatestaticfinallongserialVersionUID=1L;DimensionscreenSize;publicShellClient(){su
此文档下载收益归作者所有