File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Sockets and Internet Protocols and the fly likes Sending image from 1 computer to another. 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 "Sending image from 1 computer to another." Watch "Sending image from 1 computer to another." New topic

Sending image from 1 computer to another.

Riddhi Shah

Joined: Jun 25, 2003
Posts: 19
I am not sure this is the correct forum to post my query.
Query is related to Networking and I/O.
I have a need to send an image from one computer to another using Java.
This image should be displayed right on the receipient's desktop.
We know that if we type "net send "computer_name" "message" in Start-->Run, the "message" is displayed on the machine-computer_name", which is connected to your machine.
I need the same kind of functionality for image. I need to send an image to another computer and display it on the receipient's desktop.
I think to pass an image, I will have to convert the image to byte array and then on the receipent's end convert the byte array to image.
I am not sure how to code this. I might sound quite ignorant. I mean how do I code this logic?
I need some guidance.
jason adam
Chicken Farmer ()
Ranch Hand

Joined: May 08, 2001
Posts: 1932
There are many different ways in Java to have one computer talk to another. You can deal with low level sockets, URLs, or with RMI.
For transferring an image, you can also use a variety of methods. You most likely will want to deal with buffered streams wrapping a byte array stream. Or you could do it via file streams.
If you want to just do direct communication and not go through the steps needed for RMI, you probably want to use a Socket, and get the input and output streams from that object to read/write the file.
I'm going to send this to the Sockets and Protocols forum, since finding out how to communicate between the two computers is your first priority.
Joe Ess

Joined: Oct 29, 2001
Posts: 9188

Check out this sample code I wrote for a similar problem. Replace the sample data String with a BufferedImage and you should find it fairly easy to use Object*putStream to send it across the network. Of course in your case, the long-lived "server" process needs to be on the "client" machine so it can display the image. . .

[How To Ask Questions On JavaRanch]
I agree. Here's the link:
subject: Sending image from 1 computer to another.
It's not a secret anymore!