I am taking screenshot of my desktop and i want to know how i would go if i want to send it to php site and then display it?
I have made this and no results about streaming.
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import javax.imageio.ImageIO;
public class Stream{
static public void captureScreen() throws Exception {
Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
Rectangle screenRectangle = new Rectangle(screenSize);
Robot robot = new Robot();
BufferedImage image = robot.createScreenCapture(screenRectangle);
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
ImageIO.write(image, "png", buffer);
byte[] data = buffer.toByteArray();
try {
// open a connection to the site
URL url = new URL("http://futuretechs.eu/stream.php");
URLConnection con = url.openConnection();
// activate the output
con.setDoOutput(true);
PrintStream ps = new PrintStream(con.getOutputStream());
// send your parameters to your site
ps.print("image=" + encodeArray(data));
System.out.println(encodeArray(data));
// we have to get the input stream in order to actually send the request
con.getInputStream();
// close the print stream
ps.close();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
try{
System.out.println("[ Stream Started ]");
while(true){
Thread.currentThread().sleep(100);
Stream.captureScreen();
}
// System.out.println("[ Stream Ended ]");
}
catch(Exception e)
{
e.printStackTrace();
}
}
static String encodeArray(byte[] in) throws IOException {
StringBuffer out = new StringBuffer();
out.append(Base64Coder.encode(in, 0, in.length));
return out.toString();
}
}
How now i would send from java the byte[] to php and play it?
So it would go like this
Java Client program sends to php site the byte[] content and then the php shows it to the user who is at the site?
Thank you!
EDIT: CODE UPDATED