aspose file tools*
The moose likes Sockets and Internet Protocols and the fly likes Server that sends a set of images (5 to 10) and clients that plays them consecutively and repeats Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "Server that sends a set of images (5 to 10) and clients that plays them consecutively and repeats " Watch "Server that sends a set of images (5 to 10) and clients that plays them consecutively and repeats " New topic
Author

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

Tima Mk
Greenhorn

Joined: Mar 25, 2014
Posts: 8
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
Marshal

Joined: Mar 22, 2005
Posts: 41874
    
  63
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.


Ping & DNS - my free Android networking tools app
Tima Mk
Greenhorn

Joined: Mar 25, 2014
Posts: 8



This is the code of server sends one image to client !
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41874
    
  63
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

Joined: Mar 25, 2014
Posts: 8
So i can send stream of images without using zip file, since i want client to display and repeat them as video?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41874
    
  63
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

Joined: Mar 25, 2014
Posts: 8
Okay thank you !!
Tima Mk
Greenhorn

Joined: Mar 25, 2014
Posts: 8
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
Marshal

Joined: Mar 22, 2005
Posts: 41874
    
  63
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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Server that sends a set of images (5 to 10) and clients that plays them consecutively and repeats