I am sending Images through sockets in Java, and when both client and server are on one computer all is well, but when I run it over LAN, the resulting image is black. I take an image of the screen with the Robot class, then scale it down with AffineTransform. Client code:
BufferedImage s = null;
socket = new Socket("AJ-PC", 4444);
out = new ObjectOutputStream(socket.getOutputStream());
Robot r = new Robot();
while(true) {
s = r.createScreenCapture(new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()));
double scale = 0.75;
int w = (int) (s.getWidth() * scale);
int h = (int) (s.getHeight() * scale);
BufferedImage outImage = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
AffineTransform trans = new AffineTransform();
trans.scale(scale, scale);
Graphics2D g = outImage.createGraphics();
g.drawImage(s, trans, null);
g.dispose();
Thread.sleep(400);
out.writeObject(new SerializableImage(outImage));
}
Server code:
server = new ServerSocket(4444);
socket = server.accept();
System.out.println(socket);
in = new ObjectInputStream(socket.getInputStream());
while(running) {
bi = (SerializableImage) in.readObject();
b = true;
System.out.println("new");
panel.repaint();
}
I am using the PsExec utility from http://technet.microsoft.com/en-us/sysinternals/bb897553.aspx , and that seems to be the problem. when I don't use this to execute remotely, it runs fine.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.