Originally posted by Joe Ess:
Just open the file with a FileInputStream and write it to the socket's InputStream. On the client, do the reverse: socket's OutputStream -> FileInputStream.
Originally posted by Dan Lynch:
[QB]
Like I said above, you don't write the input stream instance to the output stream. You READ from the input stream and WRITE to the output stream. You did it on the server side correctly (except for using a Writer, as noted below).
I see you are using out.println() to write the data to the socket. Dont. It will introduce new lines into the data, which will cause havoc in a GIF. That means whatever you declared out to be is inappropriate for binary data.
My example above wasn't the best. Readers and Writers are specialized streams for use with character-based data. You want to use Streams, which don't do character conversion on the data. The same example as above, done with Streams, from the Java Tutorial:
You should take a gander at the Java IO Tutorial. Java IO is not easy to grasp at first, but once you do, you can use the same classes to do IO on sockets, files, databases, URL's. Pretty much everything.
No, images are always messed up when sent over networks. Seriously, this should be fixable if you can describe how the image is messed up. Open the file in a text editor that has a hex mode and compare it to the bytes you are receiving on the server side.Originally posted by Dan Lynch:
The image is messed up though. Is there anything I can do about this?
Arthur, where are your pants? Check under this tiny ad.
Smokeless wood heat with a rocket mass heater
https://woodheat.net
|