Click here to Skip to main content
15,881,139 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hello Friends,

My Current Project Is Remote Desktop Connection In Java Programming.
I'm Also Successfully run The Program remote screen Shot Image in client side and sent to server. Server is used this image and convert in video..

But i am access remotely desktop same as remote desktop connection in windows os.

I've attached my code.

please what should I add or modify?

Thanks...

Client Program:

Java
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package javaapplication1;

/**
 *
 * @author khan
 */
import java.awt.*;
import java.awt.image.*;
import java.io.*;
import java.net.*;
import javax.imageio.ImageIO;

public class ScreenClient {

    public static void main(String[] args) throws Exception {
    
        Socket server = new Socket("localhost", 5494);
        
        ObjectInputStream in = new ObjectInputStream(server.getInputStream());
        
        Rectangle size = (Rectangle) in.readObject();
        
        int[] rgbData = new int[(int)(size.getWidth() * size.getHeight())];
        
        for (int x = 0; x < rgbData.length;x++) {
        
            rgbData[x] = in.readInt();
        
        }
        
        in.close();
        
        server.close();
        
        BufferedImage screen = new BufferedImage((int) size.getWidth(), (int) size.getHeight(), BufferedImage.TYPE_INT_ARGB);
        
        screen.setRGB(0,0, (int) size.getWidth(), (int) size.getHeight(), rgbData, 0,(int)size.getWidth());
        
        ImageIO.write(screen, "png", new File("screen.png"));
        
    }
    
}



Server Program:


Java
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package javaapplication1;

/**
 *
 * @author khan
 */
import java.awt.*;
import java.awt.image.*;
import java.io.*;
import java.net.*;
import javax.imageio.ImageIO;

public class ScreenServer {

    public static void main(String[] args) throws Exception {
    
        Robot robot = new Robot();
        
        BufferedImage screen;
        
        while (true) {
        
            ServerSocket server = new ServerSocket(5494);
            
            Socket client = server.accept();
            
            Rectangle size = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
            
            screen = robot.createScreenCapture(size);
            
            int[] rgbData = new int[(int) (size.getWidth()*size.getHeight())];
            
            screen.getRGB(0,0, (int) size.getWidth(), (int) size.getHeight(), rgbData, 0, (int) size.getWidth());
            
            OutputStream baseOut = client.getOutputStream();
            
            ObjectOutputStream out = new ObjectOutputStream(baseOut);
            
            ImageIO.write(screen, "png", new File("orig_screen.png"));
            
            out.writeObject(size);
            
            for (int x = 0; x < rgbData.length; x++) {
            
                out.writeInt(rgbData[x]);
            
            }
            
            out.flush();
            
            server.close();
            
            client.close();
            
            out.close();
            
            baseOut.close();
            
        }
        
    }
    
}
<
Posted
Updated 15-Jan-14 0:48am
v3
Comments
Joan M 15-Jan-14 6:33am    
Pasting this here and waiting for somebody to give you an answer... won't work at all, I've updated your question to look easier to understand (code blocks), but you should explain in detail what you've tried and where are you stuck before pasting code like this. Do it and you'll get an answer. Good luck!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900