BufferedImage Distortion Over Socket?

Hello, I'm writing a remote administration tool for fun, anyhow I've added a "screen share" function, which allows me to view the machines screen real-time. The image is taken with the Robot class, loaded into a buffered image, then sent over an OutputStream via ImageIO.

It works for a bit, then the server (Receiving the images) starts displaying things such as the image attached.

Re: BufferedImage Distortion Over Socket?

Re: BufferedImage Distortion Over Socket?

I wouldn't trust using ImageIO to read directly from a stream. How about writing the image to a byte array first, then sending the size of that array, and the array over the stream so that you know exacctly what to expect when you're reading from the server side. Like so (I just modified your code a little):