This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Sending Image to Client

 
Shyam Prasad Murarka
Ranch Hand
Posts: 209
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Readers,
I need to send an image from the Server to the Client. I have successfully done so but how do I inform the Client that the entire image has been sent.
I use BufferedOutputStream on the Server side to send data to the client by reading the image file with the help of FileInputStream's read() method.
I tried sending "-1" as a marker to inform the client that the entire image has been sent. Unfortunately, since the write() method of BufferedOutputStream sends only "byte" data, the "-1" gets truncated to "255".
Because of this, the Client waits for more input from the Server leaving my program stranded after that.
 
Joe Ess
Bartender
Posts: 9214
9
Linux Mac OS X Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are thinking about a protocol, a wrapper around the data so your server and client can converse.
The simplest options off the top of my head:
-close the stream when you are done writing data, then the receiving end gets an EOF
-if you want to keep the socket open for a prolonged conversation, use the Object*putStreams to read/write Java objects
- another option is to precede any data with a value indicating the length of the message. If you are transmitting various kinds of data you could also include a value indicating which kind of data or even what kind of message you are sending.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic