Hi,
i can send and load into JPanel already and everything works perfect when is on the same computer.
The problem comes when its on another computer(LAN), screen captures is slow and sends the data(imageIcon) every second or so... it takes a lot of time to send it. the "mouse/keyboard" control works well on both Localhost/LAN almost real-time. the only problem is the screen capture :/ can anyone help me to improve the FPS?
This file is the server handler, it manages to send the Image Screen as a object...
Socket Client = null; Robot Robot = null; Rectangle Rectangle = null; boolean continueLoop = true; String nom_pc; public ServerHandler(Socket client, Robot robot, Rectangle rect,String n_pc) { this.Client = client; this.Robot = robot; Rectangle = rect; nom_pc = n_pc; start(); } @Override public void run() { ObjectOutputStream oos = null; try { oos = new ObjectOutputStream(Client.getOutputStream()); oos.writeObject(Rectangle); } catch (IOException ex) { } while (continueLoop) { BufferedImage image = Robot.createScreenCapture(Rectangle); ImageIcon imageIcon = new ImageIcon(image); try { oos.writeObject(imageIcon); oos.flush(); oos.reset(); System.out.println("Enviado Screen..."); } catch (IOException ex) { try { System.out.println("Se ha perdido conexion con el servidor remoto: " + Client.getInetAddress() + ":" + Client.getLocalPort()); continueLoop = false; Client.close(); variables_saves.PCCN_ARRAYLIST.remove(Client); variables_saves.setNombre_pc(nom_pc); if (variables_saves.getNombre_pc().equals("ConflictoIP".toLowerCase())) { variables_saves.PCCNNAME_ARRAYLIST.remove("Dirección IP Duplicada:" + Client.getInetAddress().getHostAddress()); } else if (variables_saves.getNombre_pc().equals("NoIP".toLowerCase())) { variables_saves.PCCNNAME_ARRAYLIST.remove("Desconocido"); } else if (variables_saves.getNombre_pc().equals("Anonymous")) { variables_saves.PCCNNAME_ARRAYLIST.remove("Anonymous"); } else { variables_saves.PCCNNAME_ARRAYLIST.remove(variables_saves.getNombre_pc()); } Home.Connected_pc_list.setListData(variables_saves.PCCNNAME_ARRAYLIST.toArray()); } catch (Exception e) { } } try { Thread.sleep(100); } catch (InterruptedException e) { } } }
This is the client, it's an "APPLET", its actually receive the screen and draw into a JPanel
import java.awt.Graphics; import java.awt.Image; import java.io.IOException; import java.io.ObjectInputStream; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.ImageIcon; import javax.swing.JPanel; class ScreenReciever extends Thread { private ObjectInputStream cObjectInputStream = null; private JPanel cPanel = null; private boolean continueLoop = true; public ScreenReciever(ObjectInputStream ois,JPanel p){ cObjectInputStream = ois; cPanel = p; } public void run(){ try { //Read screenshots of the client then draw them while(continueLoop){ //Recieve client screenshot and resize it to the current panel size ImageIcon imageIcon = (ImageIcon) cObjectInputStream.readObject(); System.out.println("New image recieved"); Image image = imageIcon.getImage(); image = image.getScaledInstance(cPanel.getWidth(),cPanel.getHeight() ,Image.SCALE_FAST); //Draw the recieved screenshot Graphics graphics = cPanel.getGraphics(); graphics.drawImage(image, 0, 0, cPanel.getWidth(),cPanel.getHeight(),cPanel); } } catch (IOException ex) { System.out.println("Connection with computer LOST"); try { Thread.sleep(3000); System.exit(0); } catch (InterruptedException ex1) { Logger.getLogger(ScreenReciever.class.getName()).log(Level.SEVERE, null, ex1); } } catch(ClassNotFoundException ex){ // ex.printStackTrace(); } } }
Please help me improve the code, because i don't know what to do anymore and i have to finish this proyect for next week...
One thing... i did use this method before and i had not problem, the only difference now is that Server(is a program) and client is an Applet loaded into browser...