0

我正在尝试制作一个服务器-客户端模型,在该模型中服务器可以看到客户端在其系统上所做的事情。我想通过套接字(skt)捕获和发送图像。如何显示服务器接收到的图像。

客户端线程:

screenShot = new Robot().createScreenCapture(new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()));
                    ImageIO.write(screenShot, "PNG", skt.getOutputStream());

服务器线程:

                BufferedImage image = ImageIO.read(connarray.get(0).getInputStream());
                Graphics g = image.getGraphics();
                g.drawImage(image, 500, 500, null);
4

1 回答 1

0

You don't ask an actual question here, but I could make a couple of observations.

  1. 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

        } catch(Exception ew) { }
    

    to

        } catch(Exception ew) { ew.printStackTrace(); }
    

    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.)

  2. Taking a screenshot every 1/10th of a second is going to generate a lot of load on the client and server side.

  3. There are existing (non-Java) tools for doing this kind of thing.

于 2012-06-24T06:30:18.307 回答