DESKTOP SHARING USING JAVA

Ads

 
 

Share on Google+Share on Google+

Ankur Bawiskar
DESKTOP SHARING USING JAVA
0 Answer(s)      6 years and 6 months ago
Posted in : Swing AWT

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

Ads
View Answers
Ads









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
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
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
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 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
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
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
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
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
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.... Main topics included in the PHP online Training: Installing and using
Version of co.openfin>openfin-desktop-java-adapter dependency
List of Version of co.openfin>openfin-desktop-java-adapter dependency
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
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
EasyEclipse Desktop Java
EasyEclipse Desktop Java       EasyEclipse Desktop Java For development of Desktop... - Shared platform services from Eclipse - Getting started. Java JDK
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
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
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

Ads

 
Advertisement null

Ads