Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Server that sends a set of images (5 to 10) and clients that plays them consecutively and repeats

 
Tima Mk
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello,

I'm trying to make a client/server program where server sends a stream of images (5 to 10) and clients that plays them consecutively and repeats (to simulate a video).
I wrote the code where server send one image to the client using Image IO and the server receive and display it, but I have a problem in sending stream of images and I don't know if Image IO can send stream of images or not.

any ideas!!
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ImageIO doesn't stream anything by itself - how exactly are you using it? Can you post relevant excerpts of the client and server code?

My first reaction would be: create a ZIP file containing all images and send that. That's probably easier than coming up with a protocol that sends multiple consecutive files individually.
 
Tima Mk
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



This is the code of server sends one image to client !
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I see. There is no need for ImageIO here - it transforms files to BufferedImage objects, and then back to byte[] for streaming over the connection. You should just read from a FileInputStream, and then write to the connection directly.
 
Tima Mk
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So i can send stream of images without using zip file, since i want client to display and repeat them as video?
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can, but then you need to come with some kind of protocol for client and server to use, so both sides know when one image is done, and the next one starts. That's why I suggested using a ZIP file, so that you'd have only a single file to send. This doesn't really have anything to do with using or not using ImageIO.
 
Tima Mk
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay thank you !!
 
Tima Mk
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if I made zip for file how could I send it through socket??

FileInputStream fin = new FileInputStream("E:\\pics");
ZipInputStream zip = new ZipInputStream(fin);
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can only use a ZipInputStream with a zip file, not with a directory. It is an InputStream like any other, you can use the read(byte[]) and read(byte[], int, int) methods to read its contents into a byte[] - the contents of which you can then stream to the connection.

If this was my problem, I wouldn't create a zip file at all. I would create a ZipOutputStream around conn.getOutputStream(), and then create ZipEntry objects for each file, and wrote the contents of the files directly to the ZipOutputStream.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic