Jump to content


Photo

acceso remoto


  • Please log in to reply
3 replies to this topic

#1 jhonconstantin

jhonconstantin

    Newbie

  • Miembros
  • Pip
  • 9 posts

Posted 21 November 2012 - 02:24 PM

buenas tarde antes que nada soy nuevo en java, me gustaria que si alguien a realizado al gun proyecto de acceso remoto me pudiera orientarme.
lo que quierio realizares lo sigueinte:  contrololar completamente una pc ese es el objetivo. espero contar con su ayuda. les deseo un buen dia
  • 0

#2 Fenareth

Fenareth

    Advanced Member

  • Administrador
  • 3486 posts
  • LocationMexico City

Posted 21 November 2012 - 03:22 PM

Bienvenido seas a DelphiAccess amigo jhonconstantin(y)

Qué idea tan interesante tienes para desarrollar... ahora dinos: Qué avance llevas de tu proyecto ? Tienes algunas dudas en específico ? Puedes mostrarnos algo de lo que tienes de tal manera que podamos comprender un poco mejor tu idea general ?

Saber ésto nos permitirá ayudarte de manera más rápida y eficiente...

Saludox y siéntete como en casa ! :)


  • 0

#3 jhonconstantin

jhonconstantin

    Newbie

  • Miembros
  • Pip
  • 9 posts

Posted 21 November 2012 - 05:08 PM

antes que nada gracias por responder, soy nuevo en este tema de acceso remoto pero estoy investigando de como hacerlo e encontrado algunas herramientas de java  rmi, socket, hilos... la forma de hacerlo es mediante de cliente servido pero no tengo idea.. te agradecería que me ayudaras. gracias y que dios les bendiga..XD
  • 0

#4 jhonconstantin

jhonconstantin

    Newbie

  • Miembros
  • Pip
  • 9 posts

Posted 02 January 2013 - 04:47 PM

antes que nada mil disculpa por la tardansa. hise una investigacion  de como se realiza el ciente y servidor en java para poder realizar el acceso remoto y lo que tengo hasta hora es lo siguente... este es el servidor

el archivo se lla imageserve.java
[java]

package imageserver;

public class ImageServer {

    public static void main(String[] args) {
        Servidor s = new Servidor();
    }
}[/java]
--------
este se llama Servidor.java
-----[java]
package imageserver;

import java.awt.BorderLayout;

import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.io.*;
import java.net.*;

import javax.imageio.ImageIO;
import javax.swing.*;

public class Servidor extends JFrame implements ActionListener, Runnable {
    /**
*
*/
private static final long serialVersionUID = 1L;
ServerSocket s;
    Socket con;
    ImageIcon img;
    JLabel lblImg, lblEst;
    Boolean est = false;
    ObjectInputStream entrada;
    ByteArrayInputStream bufferImg;
    BufferedImage imagen;
    JButton btnIni;
    JTextField txtPuerto;
    Thread t;
   
    public Servidor(){
        ini();
    }
   
    final void ini(){
        txtPuerto = new JTextField(5);
        txtPuerto.setText("5000");
        btnIni = new JButton("Iniciar");
        btnIni.addActionListener(this);
        lblEst = new JLabel("Esperando Iniciar");
        JPanel p = new JPanel();
       
        this.getContentPane().add(p, BorderLayout.NORTH);
       
        p.setLayout(new FlowLayout());
        p.add(new JLabel("Puerto"));
        p.add(txtPuerto);
        p.add(btnIni);
        p.add(lblEst);
       
        lblImg = new JLabel();
        this.getContentPane().add(lblImg, BorderLayout.CENTER);
       
        this.setTitle("Servidor");
        this.setSize(400, 100);
        this.setVisible(true);
        this.setLocationRelativeTo(null);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
       
       
    }   
   
    void iniServ(){
        try {
            lblEst.setText("Esperando al Cliente por el puerto: " + txtPuerto.getText());
            s = new ServerSocket(Integer.parseInt(txtPuerto.getText()));
            con = s.accept();
            if (con.isConnected()){
                btnIni.setText("Salir");
                lblEst.setText("Cliente Conectado: " + con.getRemoteSocketAddress());
                this.setBounds(0, 200, 800, 600);
                this.setLocationRelativeTo(null);
                est = true;
            }
        } catch (NumberFormatException | IOException ex) {
            System.out.println(ex.getMessage());
        }
    }
   
    void finServ()
    {
        est = false;
        try {
            con.close();
            s.close();
            this.dispose();
        } catch (Exception ex) {
            System.out.println(ex.getMessage());
        }
    }
   
    void procImagenes()
    {
        while(est){
            try{
                lblEst.setText("Conectado");
                entrada = new ObjectInputStream(con.getInputStream());
                byte[] bytesImg = (byte[]) entrada.readObject();
                bufferImg = new ByteArrayInputStream(bytesImg);
                imagen = ImageIO.read(bufferImg);
                img = new ImageIcon(imagen);
                lblImg.setIcon(img);
            }
            catch (IOException | ClassNotFoundException e){
                System.err.println(e.getMessage());
                est = false;
                lblEst.setText("Desconectado");
                this.setSize(400, 100);
                this.setLocationRelativeTo(null);
                this.remove(lblImg);
            } 
        }
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        if (e.getSource() == btnIni)
        {           
            if ("Iniciar".equals(btnIni.getText()))
            {
                if (!txtPuerto.getText().isEmpty()){
                    this.iniServ();
                    if (t == null){
                        t = new Thread(this, "ServidorImagenes");
                        t.start();
                    }
                }
                else
                {
                    lblEst.setText("Eso no es un puerto");
                }
            }
            else
            {
                this.finServ();
            }
        }
    }

    @Override
    public void run() {
        this.procImagenes();
    }

}[/java]
---------
este es el cliente y se llama  Imageclient.java
------[java]
package Imageclient;

public class ImageClient {

    public static void main(String[] args) {
        Cliente c = new Cliente();
    }
}[/java]

----------
Cliente.java
-----------[java]
package Imageclient;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.io.*;
import java.net.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;

public class Cliente extends JFrame implements ActionListener, Runnable {
    Socket c;
    Boolean est = false;
    ObjectOutputStream salida;
    ByteArrayOutputStream imgSalida;
    JButton btnIni;
    JTextField txtIp, txtPuerto;
    JLabel lblEst;
    Thread t;
   
    public Cliente()
    {   
        this.ini();
    }
   
    final void ini(){
       
        this.setLayout(new FlowLayout());
        btnIni = new JButton("Iniciar");
        btnIni.addActionListener(this);
        txtIp = new JTextField(10);
        txtIp.setText("localhost");
        txtPuerto = new JTextField(5);
        txtPuerto.setText("5000");
        lblEst = new JLabel("Esperando Iniciar");
       
        this.add(new JLabel("Ip:"));
        this.add(txtIp);
        this.add(new JLabel("Puerto:"));
        this.add(txtPuerto);
        this.add(btnIni);
        this.add(lblEst);
       
        this.setTitle("Cliente");
        this.setBounds(0, 0, 400, 100);
        this.setLocationRelativeTo(null);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setVisible(true);
    }
   
    void IniCon(){
        try {
            //Iniciar Socket para la conexion con el Servidor
                c = new Socket(txtIp.getText(), Integer.parseInt(txtPuerto.getText()));
                lblEst.setText("Estableciendo Conexion con el Servidor");
                if (c.isConnected()){
                    est = true;
                    btnIni.setText("Salir");
                    lblEst.setText("Conectado con el servidor");
                    txtPuerto.setEnabled(false);
                    txtIp.setEnabled(false);
                }
        } catch (NumberFormatException | IOException e){
            System.out.println(e.toString());
            lblEst.setText("No se puede establecer la conexion");
            est = false;
        }
    }
   
    void enviarImagenes(){
            while(est){
                try{
                    if (c != null)
                    {
                        //Iniciar el Objeto Stream con el cual se enviaran los datos
                        salida = new ObjectOutputStream(c.getOutputStream());
                        //crear el Array de Bytes del para guardar la info anterior
                        imgSalida = new ByteArrayOutputStream();
                        //Crear la Imagen y guardarlo en el objeto anterior
                        ImageIO.write(pantallazo(), "jpeg", imgSalida);
                        //Crear un Array de Bytes de la imagen capturada
                        byte[] bytesImg = imgSalida.toByteArray();
                        //Enviar el array de Bytes
                        salida.writeObject(bytesImg);
                        //vaciar Buffer
                        imgSalida.flush();
                    }
                }
                catch (Exception e){
                    System.out.println(e.getMessage());
                    lblEst.setText("Desconectado");
                    est = false;
                }
            }
    }
   
    void finCon()
    {
        est = false;
        try {
            c.close();
            this.dispose();
        } catch (Exception ex) {
            System.out.println(ex.getMessage());
        }
        lblEst.setText("Esperando Iniciar");
        txtPuerto.setEnabled(true);
    }
   
    BufferedImage pantallazo() throws Exception {
        //obtener el tamaño de la pantalla
        Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        //crear un objeto del tipo Rectangle con el tamaño obtenido
        Rectangle screenRectangle = new Rectangle(screenSize);
        //inicializar un objeto robot
        Robot r = new Robot();
        //obtener una captura de pantalla del tamaño de la pantalla
        BufferedImage image = r.createScreenCapture(screenRectangle);
       
        return image;
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        if (e.getSource() == btnIni)
        {           
            if ("Iniciar".equals(btnIni.getText()))
            {
                if (!txtPuerto.getText().isEmpty() || !txtIp.getText().isEmpty()){
                    this.IniCon();
                   
                    if (est && t == null){
                        t = new Thread(this, "ClienteImagens");
                        t.start();
                    }
                }
                else
                {
                    lblEst.setText("Direccion IP o Puerto Incorrecto");
                }
            }
            else
            {
                this.finCon();
            }
        }
    }

    @Override
    public void run() {
        this.enviarImagenes();
    }
}[/java]
este son los archivo que tengo hasta hora  lo que hace este pequeño sistema es mostra el escritorio del usuario pero el problema es que duplica la pantalla y la verda no e encontrado el error si alguien me puede ayudar a rebisar el codigo se lo gradeseria mucho  espero que alguien me ayuden...
  • 0




IP.Board spam blocked by CleanTalk.