Stream images through socket

hey all.

Okay, here's what I'm trying to achieve:

I am going to install two applications. One on the Client machine, and one on the Server machine.
I want to the user on the server machine to be able to view everything happening on the Client machine (like a video recording of it, and streamed over to the server).

I need to come up with the best method of doing this. I've come up with probably the most logical technique:

Keep printing screen on the client machine, and stream the BufferedImage's to the Server. The server then keeps updating the recieved BufferedImage's to the application (which is a JWindow, that takes up the whole screen).

Would you lot agree that this is the best/only technique of achieving this? If not, I'm open to any other suggestions.

If you agree however, that that's the best technique, then I have a couple of queries:

 1)  On the server machine, would the best method of constantly outputting the frames to the app be by using a JLabel ? (ie: JLabel jl_output = new JLabel ( [bufferedImage] );).
 2)  If I use a JLabel to store the frames, what would be the best method of updating it with the new BufferedImage? For example, I don't think that this way updates the display: jl_output = new JLabel ( [newBufferedImage] ); .. Would I need to use: repaint(); to update the display??
 3)  How would I write the BufferedImages to the Socket? Would I need to generate a byte[] array ? And write that to the Socket, then turn the Byte[] array (on the server side) into the BufferedImage ?? If so, anyone got any example code to do this???

I'm open to any and all comments/suggestions.

Thanks in advance! :-)
[r.D]
LVL 9
DrWarezzAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

OBCTCommented:
It sounds like this would require alot of bandwidth.
Anyway, you should use the javax.imageio.ImageIO class. It comes standard with J2SE 1.4.2 and up.
In this class you can write an image to Input/Output stream.
The java.awt.Robot class will supply you with a simple screen capture method.
Heres an example...

Server...
Rectangle screenSize = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
Robot robot = new Robot();
BufferedImage screenImage = robot.createScreenCapture(screenSize);

ImageIO.write(screenImage, "jpeg", socket.getOutputStream());

Client...
BufferedImage receivedImage = ImageIO.read(socket.getInputStream());

If you re-instantiate the JLabel, specifying an ImageIcon containing the buffered image in the constructor, the component should repaint itself.

I hope this helps.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
DrWarezzAuthor Commented:
Hey OBCT,
Thanks for that. This is an app that I will be running on my LAN, so I have a fair bit of bandwidth :-)

Thanks alot for the code, I shall give it a go later when I'm home.

Thanks again,
[r.D]
0
DrWarezzAuthor Commented:
right,
I tried the following (to test the update of the image in the JLabel):


-- ScaleTest.java


import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;

public class ScaleTest extends JFrame implements ActionListener {
   
    JLabel jl_testLabel = null;
   
    public ScaleTest () {
       
        super( "Scale Test" );
        setBounds( 100, 100, 200, 200 );
        setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
       
        JPanel pane = new JPanel ();
        setContentPane ( pane );
       
        jl_testLabel = new JLabel( new ImageIcon( "imageName1.jpg" ) );
       
        JButton jb_change = new JButton ( "Change" );
        jb_change.addActionListener ( this );
       
        pane.add ( jb_change );
        pane.add ( jl_testLabel );
       
        setVisible ( true );
       
    }
   
    public static void main ( String [] args ) {
        new ScaleTest().pack();
    }
   
    public void actionPerformed ( ActionEvent evt ) {
        jl_testLabel = new JLabel( new ImageIcon( "imageName2.jpg" ) );
    }
   
}


It doesn't work ... it should change the image when I click on the button "Change" ... what's up with that?!? :o\ lol

Have I done something wrong with the code? If not, do you have any other ideas? :o\

Thanks!
[r.D]
0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

OBCTCommented:
Sorry DrWarez, it turns out I was wrong.
Reconstructing the Label doesn't repaint it!!! Seems a bit stupid to me but anyway,
try this....

in the actionPerformed(ActionEvent) method, replace this...
jl_testLabel = new JLabel( new ImageIcon( "imageName2.jpg" ) );

with this...
jl_testLabel.setIcon(new ImageIcon("imageName2.jpg"));

Theres no need for repainting because the setIcon method takes care of it all.

Cheers

-OBCT
0
DrWarezzAuthor Commented:
Hey OBCT,
Thanks alot for that. It works :-)

Your help is much appreciated.
[r.D]
0
OBCTCommented:
Always glad to help :-)

Cheers

-OBCT
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.