DESKTOP SHARING USING JAVA

DESKTOP SHARING USING JAVA

Sir i have the following code for scren capturing it is capturing in png format but when i am sending it over other m/c it is taking delay of around 16 seconds..i think it is because this line of code sleep(10000); because i am making the thread to sleep for 10sec it is taking too much of time if i reduce the amt from 10000 to 2000,3000 the delay is of 5-6 sec which is manageable but after sending 4-5 snapshots of the screen when i again send the image(screenshot) error occurs i.e "OutOfMemory Error" in heap plz suggest a solution so that i can either clear or reset the heap so that the images(snapshots) are sent without any error continously

code for server:


package main;

import java.awt.BorderLayout;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Toolkit;
import java.io.*;
import java.net.*;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class RemoteDesktopServer extends JFrame implements Serializable{
ServerSocket serverSocket;
Socket socket;

public RemoteDesktopServer() {
    try {
        serverSocket = new ServerSocket(2009);
        while (true) {
            socket = serverSocket.accept();
            new ChatHandeler(socket);
        }
    } catch (IOException ex) {
        ex.printStackTrace();
    }
}

public static void main(String[] args) {
    RemoteDesktopServer server=new RemoteDesktopServer();


}
}

//========================================

class ChatHandeler extends Thread {

FileInputStream fis;
ObjectInputStream ois;
ImageIcon img;
Image image;
File file;
JFrame frame;
RemoteDesktopServer server;

//static Vector<ChatHandeler> clientsVector = new Vector<ChatHandeler>();

public ChatHandeler(Socket s) {
    //server=new RemoteDesktopServer();
    file=new File("Server.png");
    frame=new JFrame();
    try {
        //scnr = new Scanner(s.getInputStream());
        ois=new ObjectInputStream(s.getInputStream());
        //clientsVector.add(this);
        start();
    } catch (IOException ex) {
        ex.printStackTrace();
    }
}

public void run() {
    while (true) {
        try {

            img = (ImageIcon) ois.readObject();
            image= img.getImage();
            frame.add(new MyPanel(image), BorderLayout.CENTER);
            img = null;
            image = null;
            Runtime runtime= Runtime.getRuntime();
            runtime.gc();
            frame.setSize(1300, 800);
            frame.setVisible(true);
            try {
                sleep(10000);
            } catch (InterruptedException ex) {
                System.out.println(" sleep  exception");
            }
            System.out.println("Read");
        } catch (ClassNotFoundException ex) {
            //ex.printStackTrace();
            System.out.println(" Class not found exception");
        } catch (IOException ex) {
            //ex.printStackTrace();
            System.out.println("IOException");
        }
    }
}
}

class MyPanel extends JPanel {
Image image;
  public MyPanel(Image image  ) {
      this.image=image;
Toolkit kit = Toolkit.getDefaultToolkit(  );
image = kit.getImage("client.png");

  }

  public void paintComponent(Graphics g) {
    Graphics2D g2 = (Graphics2D)g;
    g2.drawImage(image, 10, 10, this);

  }


}

code for client:

package main;


//////client

import java.awt.*;
import java.io.*;
import java.net.*;
import java.util.*;
import javax.swing.*;
import java.awt.Robot;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
import org.omg.SendingContext.RunTime;
public class RemoteDesktopClient  extends JFrame implements Serializable{
public JButton btn;
//====================client
Socket mySocket;
Scanner scn;
PrintStream prntStream;
//=====================robot
Robot robot;
BufferedImage screenShot;
ImageIcon imageIcon;
String str;
FileOutputStream fos;
ObjectOutputStream oos;
File file;

public RemoteDesktopClient() {
imageIcon=new ImageIcon();
file=new File("client.png");
btn = new JButton("Send");
try {
mySocket = new Socket("192.168.1.101", 2009);
new Send(mySocket);
robot.mouseMove(1000, 800);
setSize(300, 300);
setDefaultCloseOperation(EXIT_ON_CLOSE);

setVisible(true);
//==========================client
}catch (UnknownHostException ex) {
System.out.println("UnKnown Host Exception");
} catch (IOException ex) {
System.out.println("IO Exception after unknown");
}
//==========================client
}

public static void main(String[] args) {
RemoteDesktopClient client = new RemoteDesktopClient();
}
//===========================================
class Send extends Thread {
//public  Rectangle rectangle;
public Send(Socket s) {
try {
    //scn = new Scanner(s.getInputStream());
    //rectangle = new Rectangle();
    oos = new ObjectOutputStream(mySocket.getOutputStream());
    robot = new Robot();
    start();
} catch (IOException ex) {
    ex.printStackTrace();
} catch (AWTException ex) {
    ex.printStackTrace();
}
}
public void run() {
while (true) {
    try {
     // rectangle.setSize(Toolkit.getDefaultToolkit().getScreenSize());
    screenShot = robot.createScreenCapture(new Rectangle((Toolkit.getDefaultToolkit().getScreenSize())));
//screenShot = robot.createScreenCapture(new Rectangle(800,600));


    //screenShot.se

    ImageIO.write(screenShot, "png", file);
    imageIcon=new ImageIcon(""+file);
    //imageIcon.setImage(screenShot);
    oos.writeObject(imageIcon);
    oos.flush();
    //sleep(1000);
    screenShot = null;
    Runtime runtime= Runtime.getRuntime();
    runtime.gc();
        } catch (IOException ex) {
        ex.printStackTrace();
    }
    //catch (InterruptedException ex) {
//                        ex.printStackTrace();
//                    }
    }
}
}
}

Thanks

View Answers









Related Tutorials/Questions & Answers:
DESKTOP SHARING USING JAVA
DESKTOP SHARING USING JAVA  Sir i have the following code for scren capturing it is capturing in png format but when i am sending it over other m/c it is taking delay of around 16 seconds..i think it is because this line of code
linux desktop on windows without using vn or any other ? - Java Magazine
linux desktop on windows without using vn or any other ?  linux desktop on windows without using vn or any other ?. I have a linux pc and windows... and linux are in the same network .i am trying by using using the remotedesktop
Advertisements
steps to create desktop application in java swing using eclipse with drag and drop options
steps to create desktop application in java swing using eclipse with drag and drop options  please help to create desktop application in java swing using eclipse with drag and drop and what are the plugins required
Help me to create a sharing text just like facebook using jsp servlet and oracle
Help me to create a sharing text just like facebook using jsp servlet and oracle   I tried to use lot of methods but i couldn't get the proper method to do the share option. While a person is login into the web page he can share
p2p file sharing tech - Java Server Faces Questions
p2p file sharing tech  which technology we can use to build a p2p mobile file sharing application. Is there any application through we can do file sharing on mobile
java--desktop appilication - JDBC
java--desktop appilication  when class.forName() is called ,,,a class is loaded...once after the class is loaded ..if we call class.forName, it will call the class which is already present.......what to do if we want to load
Using the Desktop class to launch a URL
Using the Desktop class to launch a URL with default browser...; Using the Desktop class to launch a URL with default browser in Java  This article describes the new Desktop API
Java Spring Desktop application
Java Spring Desktop application  Hi i am developing a desktop java spring application..It has many Jframes forms and classes...How to close one Jframe from another..Please tell... First jframe package desktopapplication2
java desktop - Java Beginners
java desktop  Hi, Iam created a desktop login application using swings. pls observe the following code: import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.sql.*; class LoginDemo{ JButton
java desktop - Java Beginners
java desktop  Hi, Iam created a desktop login application using swings. pls observe the following code: import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.sql.*; class LoginDemo{ JButton
PHP Training online in India
PHP Training online in India We are providing PHP Training online in India using desktop sharing softwares. PHP Training online is very effective way...: Installing and using WAMP server for developing PHP based applications PHP
P2P file sharing application
P2P file sharing application  Hi, I have developed a simple file sharing application in java using TCP socket. Now, the question is how do i make this application P2P? Can Distributed Hash Table (DHT) do that or there are other
Simple Java Desktop Upload application
Simple Java Desktop Upload application  I try do simple example for upload applicationtake file from c:\ put to d:\ :) PLEASE HELP
Version of co.openfin>openfin-desktop-java-adapter dependency
List of Version of co.openfin>openfin-desktop-java-adapter dependency
local host sharing on same network compute
local host sharing on same network compute  i have an desktop bill application on wamp and i want to use it on other computer on same network . computer connected with hub or switch
Java program to get the desktop Path
Java program to get the desktop Path  ... the desktop path of the system. In the java environment we can get the desktop path also with the system's property. For getting the desktop path we have to add
Create a Desktop Pane Container in Java
Create a Desktop Pane Container in Java   ... pane container in Java. The desktop pane container is a container, which has... under the desktop pane. Following figure shows the JDesktopPane component of Java
EasyEclipse Desktop Java
EasyEclipse Desktop Java       EasyEclipse Desktop Java For development of Desktop... started. Java JDK for Windows - Run Java application on Sun Java(tm
ModuleNotFoundError: No module named 'secret-sharing'
ModuleNotFoundError: No module named 'secret-sharing'  Hi, My... named 'secret-sharing' How to remove the ModuleNotFoundError: No module named 'secret-sharing' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'secret-sharing'
ModuleNotFoundError: No module named 'secret-sharing'  Hi, My... named 'secret-sharing' How to remove the ModuleNotFoundError: No module named 'secret-sharing' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'wagtail-sharing'
ModuleNotFoundError: No module named 'wagtail-sharing'  Hi, My... named 'wagtail-sharing' How to remove the ModuleNotFoundError: No module named 'wagtail-sharing' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'django-sharing'
ModuleNotFoundError: No module named 'django-sharing'  Hi, My... named 'django-sharing' How to remove the ModuleNotFoundError: No module named 'django-sharing' error? Thanks   Hi, In your python
path setting for tomcat to java for Desktop PC - JDBC
path setting for tomcat to java for Desktop PC  Hi sir, I want to connect my java programms to Database which of either sql,oracle,mysql... or configuration about the Tomcat Server in Java. Kindly visit them . We hope
Java Spring Desktop application with multiple classes and jframe
Java Spring Desktop application with multiple classes and jframe  Hi i am developing a desktop java spring application..It has many Jframes forms and classes...How to close one Jframe from another..Please tell... First jframe
Maven Dependency openfin-desktop-java-adapter >> 3.0.1.2
You should include the dependency code given in this page to add Maven Dependency of co.openfin >> openfin-desktop-java-adapter version3.0.1.2 in your project
Maven Dependency openfin-desktop-java-adapter >> 3.0.1.3
You should include the dependency code given in this page to add Maven Dependency of co.openfin >> openfin-desktop-java-adapter version3.0.1.3 in your project
Maven Dependency openfin-desktop-java-adapter >> 4.40.2.5
You should include the dependency code given in this page to add Maven Dependency of co.openfin >> openfin-desktop-java-adapter version4.40.2.5 in your project
Maven Dependency openfin-desktop-java-adapter >> 4.40.2.6
You should include the dependency code given in this page to add Maven Dependency of co.openfin >> openfin-desktop-java-adapter version4.40.2.6 in your project
Maven Dependency openfin-desktop-java-adapter >> 4.40.2.8
You should include the dependency code given in this page to add Maven Dependency of co.openfin >> openfin-desktop-java-adapter version4.40.2.8 in your project
Maven Dependency openfin-desktop-java-adapter >> 4.40.2.9
You should include the dependency code given in this page to add Maven Dependency of co.openfin >> openfin-desktop-java-adapter version4.40.2.9 in your project
Maven Dependency openfin-desktop-java-adapter >> 5.44.2.0
You should include the dependency code given in this page to add Maven Dependency of co.openfin >> openfin-desktop-java-adapter version5.44.2.0 in your project
Maven Dependency openfin-desktop-java-adapter >> 5.44.2.2
You should include the dependency code given in this page to add Maven Dependency of co.openfin >> openfin-desktop-java-adapter version5.44.2.2 in your project
Maven Dependency openfin-desktop-java-adapter >> 5.44.2.3
You should include the dependency code given in this page to add Maven Dependency of co.openfin >> openfin-desktop-java-adapter version5.44.2.3 in your project
Maven Dependency openfin-desktop-java-adapter >> 5.44.2.4
You should include the dependency code given in this page to add Maven Dependency of co.openfin >> openfin-desktop-java-adapter version5.44.2.4 in your project
Maven Dependency openfin-desktop-java-adapter >> 5.44.3.1
You should include the dependency code given in this page to add Maven Dependency of co.openfin >> openfin-desktop-java-adapter version5.44.3.1 in your project
Maven Dependency openfin-desktop-java-adapter >> 5.44.3.2
You should include the dependency code given in this page to add Maven Dependency of co.openfin >> openfin-desktop-java-adapter version5.44.3.2 in your project
Maven Dependency openfin-desktop-java-adapter >> 5.44.3.4
You should include the dependency code given in this page to add Maven Dependency of co.openfin >> openfin-desktop-java-adapter version5.44.3.4 in your project
Maven Dependency openfin-desktop-java-adapter >> 5.44.3.6
You should include the dependency code given in this page to add Maven Dependency of co.openfin >> openfin-desktop-java-adapter version5.44.3.6 in your project
Maven Dependency openfin-desktop-java-adapter >> 6.0.0.1
You should include the dependency code given in this page to add Maven Dependency of co.openfin >> openfin-desktop-java-adapter version6.0.0.1 in your project
Maven Dependency openfin-desktop-java-adapter >> 6.0.0.2
You should include the dependency code given in this page to add Maven Dependency of co.openfin >> openfin-desktop-java-adapter version6.0.0.2 in your project
Maven Dependency openfin-desktop-java-adapter >> 6.0.1.0
You should include the dependency code given in this page to add Maven Dependency of co.openfin >> openfin-desktop-java-adapter version6.0.1.0 in your project
Maven dependency for com.axiastudio - zoefx-desktop version 0.2.1 is released. Learn to use zoefx-desktop version 0.2.1 in Maven based Java projects
- zoefx-desktop version 0.2.1 in Java projects. Follow the step by step tutorial for using the latest version of com.axiastudio - zoefx-desktop in your Maven...-desktop version 0.2.1 java library in your project. ADS_TO_REPLACE_2 Now you can
Maven dependency for com.axiastudio - zoefx-desktop version 0.2.0 is released. Learn to use zoefx-desktop version 0.2.0 in Maven based Java projects
- zoefx-desktop version 0.2.0 in Java projects. Follow the step by step tutorial for using the latest version of com.axiastudio - zoefx-desktop in your Maven...-desktop version 0.2.0 java library in your project. ADS_TO_REPLACE_2 Now you can
Maven dependency for co.paralleluniverse - capsule-desktop version 0.1.0 is released. Learn to use capsule-desktop version 0.1.0 in Maven based Java projects
? Steps to use  co.paralleluniverse - capsule-desktop version 0.1.0 in Java... of capsule-desktop released The developers of   co.paralleluniverse - capsule-desktop project have released the latest version of this library on 10 Sep 2015
Maven dependency for com.rhcloud - timemanager-desktop version 1.3 is released. Learn to use timemanager-desktop version 1.3 in Maven based Java projects
- timemanager-desktop version 1.3 in Java projects. Follow the step by step tutorial for using the latest version of com.rhcloud - timemanager-desktop in your... - timemanager-desktop version 1.3 java library in your project. ADS_TO_REPLACE_2
Maven dependency for com.rhcloud - timemanager-desktop version 1.4 is released. Learn to use timemanager-desktop version 1.4 in Maven based Java projects
- timemanager-desktop version 1.4 in Java projects. Follow the step by step tutorial for using the latest version of com.rhcloud - timemanager-desktop in your... - timemanager-desktop version 1.4 java library in your project. ADS_TO_REPLACE_2
Maven dependency for com.jalalkiswani - jk-desktop version 0.0.2 is released. Learn to use jk-desktop version 0.0.2 in Maven based Java projects
use this version ( com.jalalkiswani - jk-desktop version 0.0.2 ) in their Java...-desktop version 0.0.2 in Java projects. Follow the step by step tutorial for using the latest version of com.jalalkiswani - jk-desktop in your Maven/Gradle
iphone video sharing in facebook, email, Twitter
iphone video sharing in facebook, email, Twitter  Hi, I need sample video sharing iphone development codes --Thanks in advance
ModuleNotFoundError: No module named 'django-file-sharing'
ModuleNotFoundError: No module named 'django-file-sharing'  Hi, My... named 'django-file-sharing' How to remove the ModuleNotFoundError: No module named 'django-file-sharing' error? Thanks   Hi
ModuleNotFoundError: No module named 'django-file-sharing'
ModuleNotFoundError: No module named 'django-file-sharing'  Hi, My... named 'django-file-sharing' How to remove the ModuleNotFoundError: No module named 'django-file-sharing' error? Thanks   Hi

Ads