I've done something similar (over a socket connection) by using a byte array:
Code:
Socket mySock = new Socket("127.0.0.1", 3000);
Image bi = this.createImage(this.getSize().width-180, this.getSize().height);
printAll(bi.getGraphics());
String done = "done";
OutputStream out = mySock.getOutputStream();
GifEncoder myGif = new GifEncoder (bi, out, true);
myGif.encode();
out.write(done.getBytes());
I used "done" to indicate the end of the image. I used the ACME encoders, but back then I didn't know about JAI.
And how about moving this to the programming forum?