java里面的Robot类可以完成截图的功能,借助于这点,我尝试着做了一个简陋的桌面监控程序,运行了下,感觉速度还可以,还有很大的优化空间的,比如用udp协议取代tcp等。代码也写的不是很优雅,只在娱乐了。

实现原理其实很简单,在被监视者的机器上,运行一个线程,每隔一段时间就自动截图,并把截图压缩发送到指定的机器上;在监视机器上,也是运行一个线程,接收发送过来的图片包,解压,并绘制到当前的窗口上。这样就基本完成了。

public class Server extends Thread {private Dimension screenSize;private Rectangle rectangle;private Robot robot;public Server() {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("192.168.1.100", 5001);// 连接远程IPBufferedImage image = robot.createScreenCapture(rectangle);// 捕获制定屏幕矩形区域os = new ZipOutputStream(socket.getOutputStream());// 加入压缩流// os = new ZipOutputStream(new FileOutputStream("C:/1.zip"));os.setLevel(9);os.putNextEntry(new ZipEntry("test.jpg"));JPEGCodec.createJPEGEncoder(os).encode(image);// 图像编码成JPEGos.close();Thread.sleep(50);// 每秒20帧} 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 Server().start();}
}

客户端:

public class Client extends JFrame {private static final long serialVersionUID = 1L;Dimension screenSize;public Client() {super();screenSize = Toolkit.getDefaultToolkit().getScreenSize();this.setSize(800, 640);Screen p = new Screen();Container c = this.getContentPane();c.setLayout(new BorderLayout());c.add(p, SwingConstants.CENTER);new Thread(p).start();SwingUtilities.invokeLater(new Runnable(){public void run() {setVisible(true);}});}public static void main(String[] args) {new Client();}class Screen extends JPanel implements Runnable {private static final long serialVersionUID = 1L;private Image cimage;public void run() {ServerSocket ss = null;try {ss = new ServerSocket(5001);// 探听5001端口的连接while (true) {Socket s = null;try {s = ss.accept();ZipInputStream zis = new ZipInputStream(s.getInputStream());zis.getNextEntry();cimage = ImageIO.read(zis);// 把ZIP流转换为图片repaint();} catch (Exception e) {e.printStackTrace();} finally {if (s != null) {try {s.close();} catch (IOException e) {e.printStackTrace();}}}}} catch (Exception e) {} finally {if (ss != null) {try {ss.close();} catch (IOException e) {e.printStackTrace();}}}}public Screen() {super();this.setLayout(null);}public void paint(Graphics g) {super.paint(g);Graphics2D g2 = (Graphics2D) g;g2.drawImage(cimage, 0, 0, null);}}
}

转帖:http://flypig.iteye.com/blog/383010

-------------------------------------------------------------------------------------------------------------------------------

1) RemoteClient

Connect to Server
Collapse|Copy Code

 System.out.println("Connecting to server ..........");socket = new Socket(ip, port);System.out.println("Connection Established.");  
Capture Desktop Screen then Send it to the Server Periodically

In ScreenSpyer class, Screen is captured using  createScreenCapture method inRobot class and it accepts a Rectangle object which carries screen dimension. If we try to send image object directly using serialization, it will fail because it does not implementSerializable interface. That is why we have to wrap it using the ImageIconclass as shown below:

Collapse|Copy Code
while(continueLoop){//Capture screenBufferedImage image = robot.createScreenCapture(rectangle);/* I have to wrap BufferedImage with ImageIcon because * BufferedImage class does not implement Serializable interface*/ImageIcon imageIcon = new ImageIcon(image);//Send captured screen to the servertry {System.out.println("before sending image");oos.writeObject(imageIcon);oos.reset(); //Clear ObjectOutputStream cacheSystem.out.println("New screenshot sent");} catch (IOException ex) {ex.printStackTrace();}//wait for 100ms to reduce network traffictry{Thread.sleep(100);}catch(InterruptedException e){e.printStackTrace();}}
Receive Server Events then call Robot Class Methods to Execute these Events
Collapse|Copy Code
while(continueLoop){//receive commands and respond accordinglySystem.out.println("Waiting for command");int command = scanner.nextInt();System.out.println("New command: " + command);switch(command){case -1:robot.mousePress(scanner.nextInt());break;case -2:robot.mouseRelease(scanner.nextInt());break;case -3:robot.keyPress(scanner.nextInt());break;case -4:robot.keyRelease(scanner.nextInt());break;case -5:robot.mouseMove(scanner.nextInt(), scanner.nextInt());break;}}

2) RemoteServer

Wait for Clients Connections
Collapse|Copy Code
//Listen to server port and accept clients connectionswhile(true){Socket client = sc.accept();System.out.println("New client Connected to the server");//Per each client create a ClientHandlernew ClientHandler(client,desktop);}
Receive Client Desktop Screenshots and Display them
Collapse|Copy Code

while(continueLoop){//Receive client screenshot and resize it to the current panel sizeImageIcon imageIcon = (ImageIcon) cObjectInputStream.readObject();System.out.println("New image received");Image image = imageIcon.getImage();image = image.getScaledInstance(cPanel.getWidth(),cPanel.getHeight(),Image.SCALE_FAST);//Draw the received screenshotGraphics graphics = cPanel.getGraphics();graphics.drawImage(image, 0, 0, cPanel.getWidth(),cPanel.getHeight(),cPanel);
}
Handle Mouse and Key Events then Send them to the Client Program to Simulate them

In ClientCommandsSender class, when mouse is moved, x and y values are sent to the client but we have to take into consideration the size difference between clients' screen size and  server's panel size, that is why we have to multiply by a certain factor as shown in the following code:

Collapse|Copy Code
   public void mouseMoved(MouseEvent e) {double xScale = clientScreenDim.getWidth()/cPanel.getWidth();System.out.println("xScale: " + xScale);double yScale = clientScreenDim.getHeight()/cPanel.getHeight();System.out.println("yScale: " + yScale);System.out.println("Mouse Moved");writer.println(EnumCommands.MOVE_MOUSE.getAbbrev());writer.println((int)(e.getX() * xScale));writer.println((int)(e.getY() * yScale));writer.flush();}public void mousePressed(MouseEvent e) {System.out.println("Mouse Pressed");writer.println(EnumCommands.PRESS_MOUSE.getAbbrev());int button = e.getButton();int xButton = 16;if (button == 3) {xButton = 4;}writer.println(xButton);writer.flush();}public void mouseReleased(MouseEvent e) {System.out.println("Mouse Released");writer.println(EnumCommands.RELEASE_MOUSE.getAbbrev());int button = e.getButton();int xButton = 16;if (button == 3) {xButton = 4;}writer.println(xButton);writer.flush();}public void keyPressed(KeyEvent e) {System.out.println("Key Pressed");writer.println(EnumCommands.PRESS_KEY.getAbbrev());writer.println(e.getKeyCode());writer.flush();}public void keyReleased(KeyEvent e) {System.out.println("Mouse Released");writer.println(EnumCommands.RELEASE_KEY.getAbbrev());writer.println(e.getKeyCode());writer.flush();}

转帖:http://www.codeproject.com/KB/IP/RemoteAdminJava.aspx

java实现远程桌面监控相关推荐

  1. 远程桌面监控系统java_基于Java的远程桌面监控源代码

    <基于Java的远程桌面监控源代码>由会员分享,可在线阅读,更多相关<基于Java的远程桌面监控源代码(43页珍藏版)>请在人人文库网上搜索. 1.基于Java的远程桌面监控源 ...

  2. java实现远程桌面

    java实现远程桌面 控制端将鼠标事件传递到服务端 服务端拿到鼠标事件之后传输到客户端 客户端拿到鼠标事件之后,通过robot类即可完成,并且截屏将图片发给服务器,服务器再发给控制端 被我简化之后得到 ...

  3. Java实现远程桌面连接

    最近因为项目的原因,需要在系统(基于Java语言的)中调用远程桌面连接登录到其它三方系统,于是需要采用Java实现远程桌面连接.Java嘛,开源代码很多,于是搜集资料,找到了一个不错的开源Java R ...

  4. java远程监控系统代码_[源码和文档分享]基于JAVA的远程屏幕监控系统

    远程屏幕监控系统在生活中是很常见的,学校机房的机房管理系统.PC版QQ的远程演示功能等都属于远程屏幕监控系统.监控系统的原理是通过客户端不断的截取屏幕发送到服务器端,服务器端进而将画面呈现出来的过程. ...

  5. java版远程桌面控制(简约版)

    这个版本是通过截取桌面图片来显示远程桌面,有一个很明显的问题就是图片大小,我尝试过一些方式,但是效果都不太好,所以准备放弃这种方式进行最终实现,具体说明下我使用了那些方式去缩小图片大小... 1. 直 ...

  6. java 连接远程桌面_Java实现远程桌面(参赛作品)

    [实例简介] 本人参赛作品,纯java实现多台电脑间的远程桌面连接. [实例截图] [核心代码] javaSE实现远程桌面 └── javaSE实现远程桌面 ├── 1.程序介绍 │   └── AI ...

  7. Java实现远程服务器监控,【Java】监控远程服务器JVM

    今天在用JMeter进行测试的时候,发现线程并发量到50的时候会导致阻塞情况,于是需要监控远程JVM,那么如何监控远程JVM呢? 首先,找到启动计量引擎的sh文件,例如我目前的计量引擎启停文件为str ...

  8. 基于JAVA的远程屏幕监控系统

    摘 要 远程屏幕监控系统在生活中是很常见的,学校机房的机房管理系统.PC版QQ的远程演示功能等都属于远程屏幕监控系统.监控系统的原理是通过客户端不断的截取屏幕发送到服务器端,服务器端进而将画面呈现出来 ...

  9. java wmi远程桌面服务器_WMI实现远程监控多台windows服务器

    简介 WMI简介: WMI(Windows Management Instrumentation,Windows 管理规范)是一项核心的 Windows 管理技术:用户可以使用 WMI 管理本地和远程 ...

  10. Windows server 2019 简体中文版简单设置远程桌面访问

    以前Windows server 系统都要再电脑-属性里面设置然后再防火墙位置设置,远程桌面才能访问.现在Windows server 2019 简化流程,只需要在设置-显示-远程桌面就可以设置了.不 ...

最新文章

  1. MIT开发的一款最新Chrome插件,功能远超OCR软件,可快速识别和复制图中文字
  2. c#中页面之间传值传参的六种方法
  3. MSMQ消息队列安装
  4. FLEX实例:GOOGLE地图.
  5. SAP Leonardo机器学习如何获取模型存储的实际地址
  6. The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
  7. mysql 打开远程服务
  8. Curvilinear structure detections
  9. MATLAB学习笔记(十三)
  10. import sys是什么意思_学了半天,import 到底在干啥?
  11. 项目四管理计算机中的资源,第十七章-计算机在项目管理中的应用PPT课件.ppt
  12. 2022最新Java面试宝典(史上最全,BAT大厂面试必备,用心看完该篇就够了,建议先关注点赞加收藏)
  13. 联想小新i1000拆机图解_联想小新笔记本拆机解析
  14. 基于toolbox_calib工具箱的相机标定matlab仿真
  15. 两道2016年美国高中数学竞赛题
  16. ProxySQL 配置详解及读写分离(+GTID)等功能说明 (完整篇)1
  17. 2021-05-18
  18. ngx.var与ngx.ctx的区别
  19. 【数据结构Python描述】手动实现一个list列表类并分析常用操作时间复杂度
  20. 客户体验改善计划的用户注销通知导致服务器自动重启

热门文章

  1. 关于 Pycharm 2019.2 版本出现等宽字体对不齐的问题的解决方法
  2. 迅雷极速版任务出错的解决办法(亲测可用)
  3. Photoshop插件-证件照-白红蓝底-PS插件-脚本开发
  4. 分享帝国CMS采集教程(图文详解)
  5. 杰奇小说2.3独家定制版淡绿唯美模板自动采集关关采集器带WAP
  6. 一阶惯性环节如何实现跟踪性能与滤波性能共存(二)
  7. c语言如何开发应用程序,怎样用c语言编写软件?如许多小的程序。
  8. 你的喜爱——软件测试方法和技术
  9. Java Web项目源码整合开发大合集
  10. 侠客风云传服务器维护,侠客风云传服务器地址