Java program works in Windows but not in Mac -


hi have done program send screen capture on socket. well, works if take screen capture in mac , send windows pc(7, xp doest work), if want take screen capture in windows , send mac send part of file... here client

public class enviar {  private static int port = 3460; /* port connect */ private static string host = "192.168.1.135"; /* host connect */      private bufferedreader in = null; private static printwriter outr = null; private static socket server; private static outputstream outfile; private static inputstream infile;   public static void main (string[] args) throws ioexception, interruptedexception {          socket server = null;         inetaddress ina = inetaddress.getbyname(host);          while (true) {         try {             server = new socket(ina, port);             if (server != null) {                  break;              }         } catch (ioexception e) {              //system.exit(1);             thread.sleep(1000);         }         }              printwriter out = new printwriter(server.getoutputstream(), true);         outfile = server.getoutputstream();          bufferedreader in = new bufferedreader(new inputstreamreader(server.getinputstream()));          infile = server.getinputstream();     outr = new printwriter(server.getoutputstream(), true);     outr.flush();     string msg;          while (true){     try {          while ((msg = in.readline()) != null) {             system.out.println(msg + "2");             if (msg.equals("screen")) {                  outr.println("screenon");                  outr.flush();                  try                  {                 server();                   }                     catch(exception e)                  {                  e.printstacktrace();                  }             }          }      } catch (ioexception e) {       system.exit(0);     }     }     }   static void server() throws exception {     capturescreen("screencapture.png");           inputstream infile = new fileinputstream("screencapture.png");             copy(infile, outfile);           infile.close();           system.out.println("mandado");     }       static void copy(inputstream in, outputstream out) throws ioexception {         byte[] buf = new byte[8192];         int len = 0;         while ((len = in.read(buf)) != -1) {             out.write(buf, 0, len);         }     }      static public void capturescreen(string filename) throws exception {         string osz = system.getproperty("os.name");         if (osz.equals("mac os x")) {              system.setproperty("apple.awt.uielement", "true");         }     dimension screensize = java.awt.toolkit.getdefaulttoolkit().getscreensize();     rectangle screenrectangle = new rectangle(screensize);     robot robot = new robot();     bufferedimage image = robot.createscreencapture(screenrectangle);     imageio.write(image, "png", new file(filename));     } 

}

and server

public class recibir {     private  static socket client;     private static bufferedreader in ;     private static printwriter out;     private static outputstream outfile;     private static inputstream infile;     static int port = 3460;     static serversocket server;  public static void main(string args[]) throws interruptedexception, ioexception {     try {         server = new serversocket(port);         server.setsotimeout(1000);      } catch (ioexception e) {         system.out.println("could not listen on port:" + port);     }      system.out.println("bitch2");     while (true){        try {          client = server.accept();          in = new bufferedreader(new inputstreamreader(client.getinputstream()));         infile = client.getinputstream();          out = new printwriter(client.getoutputstream(), true);         string msg;          out.println("screen");         if ((msg = in.readline()) != null) {             if (msg.equals("screenon")){              client();             }          }               } catch (ioexception e) {              }     }        } static void client() throws ioexception {     outputstream outfile = new fileoutputstream("copied.png",false);     copyscreen(infile, outfile);     outfile.close();      //infile.close();     system.out.println("guardado");  }  static void copyscreen(inputstream in, outputstream out) throws ioexception {     byte[] buf = new byte[8192];     int len = 0;     int bytesread = 0, counter = 0;       while (bytesread >= 0) {         bytesread = in.read(buf);         if (bytesread >= 0) {             out.write(buf, 0, bytesread);             counter += bytesread;             system.out.println("total bytes read: " +                                             counter);         }         if (bytesread < 1024) {             out.flush();             break;          }      }  } 

}


Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -