Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Swing-AWT DESKTOP SHARING USING JAVA
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Ankur Bawiskar
DESKTOP SHARING USING JAVA
0 Answer(s)      3 years and 8 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


Advertisement
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
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
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
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
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 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
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
EasyEclipse Desktop Java
EasyEclipse Desktop Java       EasyEclipse Desktop Java For development of Desktop... - Shared platform services from Eclipse - Getting started. Java JDK
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
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
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
desktop application
desktop application  how to transfer data swing text field to browser text field to their corresponding label/caption. please reply as soon as possible. thanks vijay
Google Desktop Search
Google Desktop Search     ... plug-in for Eclipse. Instead of using the default (and kind-of slow) File search capabilities, this plug-in uses the Google Desktop Search Engine instead
How can I open my Java desktop app by clicking on its file?
How can I open my Java desktop app by clicking on its file?  How can I open my Java desktop app by clicking on the file it creates? This app creates files when selecting its "Save as" option with an extension specificaly defined
Works when run from desktop but....
Works when run from desktop but....  I used the code provided here for a pie chart using swing in Java, and when I saved it to my desktop, it ran... all using incompatible types, continuing to say, *required: double found: object
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
Remote desktop access - JSP-Servlet
Remote desktop access  Hello everyone Thank a lot for all the reply given before i have my 4th question which is about Remote desktop... reply me Thank a lots in advance   I forgot to say i am using jsp
Remote Desktop Services
component of RDS allows virtual desktops hosting by using RemoteApp and Desktop...Remote Desktop Services Formerly known as Terminal Services in Windows Server 2008, the Remote Desktop Services in Windows Server 2008 R2 is Microsoft
Remote mobile desktop - MobileApplications
Remote mobile desktop  I am doing my research to implement a java mobile application to access another remote mobile phone with the authentication.This application will have to use the service provider's network and a server
Remote Desktop Setting in Windows 8
the network by enabling the Remote Desktop Connection in your PC. 1. To configure 'Remote Desktop Connection' on your Windows 8 installed PC, first of all... running Remote Desktop with Network Level Authentication (recommended
ssl comunication between a desktop application and a web application
ssl comunication between a desktop application and a web application  Hi Lusiano, I am trying to implement a ssl comunication between a desktop application and a web application. can you please share code with me. Please
using eval in Java
using eval in Java  using eval in Java
write a programm using java
write a programm using java  print the following using java programming
Advertisements
 

 

 

DMCA.com