• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Sending Image to Client

 
Ranch Hand
Posts: 209
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic