proyecto_rmi_2011_ii

Upload: juanloganfernando

Post on 11-Jul-2015

27 views

Category:

Documents


0 download

DESCRIPTION

Universidad: Ricardo Palma Curso: Redes y Comunicacion de datos IIAlumno: Juan Fernando Malquichagua CanalesProfesor: Pedro Muñoz IbarracenaTema: Documento de Proyecto de Laboratorio de RMI

TRANSCRIPT

UNIVERSIDAD RICARDO PALMA INGENIERIA INFORMATICA

Profesor: Muoz Ibrcena, Pedro Alumno: Malquichagua Canales, Juan Curso: Redes y Comunicacin de Datos II Tema: Proyecto de Laboratorio RMI

20111

RMI.3 CODIGO.4 MANUAL..18

2

RMI (Java Remote Method Invocation) es un mecanismo ofrecido por Java para invocar un mtodo de manera remota. Forma parte del entorno estndar de ejecucin de Java y proporciona un mecanismo simple para la comunicacin de servidores en aplicaciones distribuidas basadas exclusivamente en Java. Si se requiere comunicacin entre otras tecnologas debe utilizarse CORBA o SOAP en lugar de RMI. RMI se caracteriza por la facilidad de su uso en la programacin por estar especficamente diseado para Java; proporciona paso de objetos por referencia (no permitido por SOAP), recoleccin de basura distribuida (Garbage Collector distribuido) y paso de tipos arbitrarios (funcionalidad no provista por CORBA). A travs de RMI, un programa Java puede exportar un objeto, con lo que dicho objeto estar accesible a travs de la red y el programa permanece a la espera de peticiones en un puerto TCP. A partir de ese momento, un cliente puede conectarse e invocar los mtodos proporcionados por el objeto. La invocacin se compone de los siguientes pasos:

Encapsulado (marshalling) de los parmetros (utilizando la funcionalidad de serializacin de Java). Invocacin del mtodo (del cliente sobre el servidor). El invocador se queda esperando una respuesta. Al terminar la ejecucin, el servidor serializa el valor de retorno (si lo hay) y lo enva al cliente. El cdigo cliente recibe la respuesta y contina como si la invocacin hubiera sido local.

3

CLASE VideosRMIImplpackage servidor; import java.io.IOException; import java.rmi.*; import java.rmi.server.UnicastRemoteObject; import servicios.RecibirVideosRMI; import com.csvreader.CsvReader; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import javax.swing.JOptionPane; public class VideosRMIImpl extends UnicastRemoteObject implements RecibirVideosRMI { private String rutaCSV="J:\ \ Redes 2\\Proyecto RMI\\Programa\\Base de Datos"; private String rutaVideos="J:\\Redes 2\\Proyecto RMI\\Programa\\Peliculas"; private boolean servidorVideosActivo, servidorBDActivo; public VideosRMIImpl(String name) throws RemoteException { super(); try { Naming.rebind(name, this); } catch (Exception e) { System.out.println("Error: " + e); } } public String getListadoDeVideos() throws RemoteException { String resultado = ""; if (servidorBDActivo) { try { CsvReader reader = new CsvReader(rutaCSV); while (reader.readRecord()) { String nomArchivo = reader.get(0); String nomPelicula = reader.get(1); String protagonista = reader.get(2); resultado += nomArchivo + " - " + nomPelicula + " - " + protagonista + "\n"; } return resultado; } catch (IOException e) { resultado = "No se encontraron registros"; JOptionPane.showMessageDialog(null, "Error (" + e.getMessage() + ")", "Mensaje", JOptionPane.INFORMATION_MESSAGE); } } return "Servidor no iniciado"; } public byte[] getVideo(String nomVideo) throws RemoteException { if (servidorVideosActivo) { FileInputStream fis; ByteArrayOutputStream bos = new ByteArrayOutputStream();

4

byte[] buf = new byte[1024]; byte[] video; try { fis = new FileInputStream(new File(rutaVideos + "\\" + nomVideo)); for (int readNum; (readNum = fis.read(buf)) != -1;) { bos.write(buf, 0, readNum); System.out.println("read " + readNum + " bytes,"); } } catch (FileNotFoundException ex) { JOptionPane.showMessageDialog(null, ex); } catch (IOException ex) { JOptionPane.showMessageDialog(null, ex); } video = bos.toByteArray(); return video; } return new byte[1]; } public void setRutaSCV(String ruta){ rutaCSV=ruta; } public void setRutaVideos(String ruta){ rutaVideos=ruta; } public void setBDActivo(boolean opcion){ servidorBDActivo=opcion; } public void setVideosActivo(boolean opcion){ servidorVideosActivo=opcion; } }

CLASE RecibirVideosRMIpackage servicios; public interface RecibirVideosRMI extends java.rmi.Remote { String getListadoDeVideos()throws java.rmi.RemoteException; byte[] getVideo(String nomVideo)throws java.rmi.RemoteException; }

FORM ClienteDePeliculaspackage cliente; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import javax.swing.*; import java.rmi.*; import servicios.RecibirVideosRMI;

5

public class ClienteDePeliculas extends javax.swing.JFrame { /** Creates new form Main */ public ClienteDePeliculas() { initComponents(); } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // private void initComponents() { jLabel1 = new javax.swing.JLabel(); txtIP = new javax.swing.JTextField(); jLabel2 = new javax.swing.JLabel(); jTextField2 = new javax.swing.JTextField(); btnPedirPelicula = new javax.swing.JButton(); btnMostrarPeliculas = new javax.swing.JButton(); txtPedirPelicula = new javax.swing.JTextField(); jScrollPane1 = new javax.swing.JScrollPane(); jTextArea1 = new javax.swing.JTextArea(); txtRuta = new javax.swing.JTextField(); jLabel4 = new javax.swing.JLabel(); jTextField1 = new javax.swing.JTextField(); btnGuardarEn = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); setTitle("Cliente"); setResizable(false); addWindowListener(new java.awt.event.WindowAdapter() { public void windowOpened(java.awt.event.WindowEvent evt) { formWindowOpened(evt); } }); jLabel1.setText("Conectar a:"); txtIP.setText("localhost"); jLabel2.setText("Puerto de BD"); jTextField2.setText("6000"); btnPedirPelicula.setText("Pedir video"); btnPedirPelicula.setEnabled(false); btnPedirPelicula.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnPedirPeliculaActionPerformed(evt); } }); btnMostrarPeliculas.setText("Mostrar Pelculas"); btnMostrarPeliculas.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnMostrarPeliculasActionPerformed(evt);

6

} }); txtPedirPelicula.setText("nombre del video"); txtPedirPelicula.setEnabled(false); jTextArea1.setColumns(20); jTextArea1.setRows(5); jScrollPane1.setViewportView(jTextArea1); txtRuta.setText("Seleccione carpeta"); txtRuta.setEnabled(false); jLabel4.setText("Puerto de peliculas"); jTextField1.setText("6001"); btnGuardarEn.setText("Guardar en"); btnGuardarEn.setEnabled(false); btnGuardarEn.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnGuardarEnActionPerformed(evt); } }); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addComponent(btnGuardarEn) .addGap(18, 18, 18) .addComponent(txtRuta, javax.swing.GroupLayout.DEFAULT_SIZE, 124, Short.MAX_VALUE)) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, 116, Short.MAX_VALUE) .addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jLabel1)) .addGap(10, 10, 10) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(txtIP, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false) .addComponent(jTextField1, javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jTextField2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)))) .addGroup(layout.createSequentialGroup() .addComponent(btnPedirPelicula) .addGap(18, 18, 18) .addComponent(txtPedirPelicula, javax.swing.GroupLayout.DEFAULT_SIZE, 126, Short.MAX_VALUE))) .addGap(23, 23, 23) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(btnMostrarPeliculas) .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 331, Short.MAX_VALUE)) .addContainerGap()) );

7

layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(txtIP, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel1) .addComponent(btnMostrarPeliculas)) .addGap(3, 3, 3) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel2)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel4)) .addGap(18, 18, 18) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(btnPedirPelicula) .addComponent(txtPedirPelicula, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(btnGuardarEn) .addComponent(txtRuta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))) .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 114, javax.swing.GroupLayout.PREFERRED_SIZE)) .addContainerGap(34, Short.MAX_VALUE)) ); pack(); }// servicios.RecibirVideosRMI calc; private void btnMostrarPeliculasActionPerformed(java.awt.event.ActionEvent evt) { String host = txtIP.getText(); try { calc = (RecibirVideosRMI) Naming.lookup("rmi://" + host + "/consult"); } catch (Exception e) { System.out.println("error:"+e); } try { jTextArea1.setText(calc.getListadoDeVideos()); txtRuta.setEnabled(true); btnGuardarEn.setEnabled(true); //btnMostrarPeliculas.setEnabled(false); } catch (Exception e) { JOptionPane.showMessageDialog(null, "Error (" + e.getMessage() + ")", "Mensaje", JOptionPane.INFORMATION_MESSAGE); }

8

} private void btnPedirPeliculaActionPerformed(java.awt.event.ActionEvent evt) { //boton Pedir esta pelicula... String host = txtIP.getText(); String file=txtPedirPelicula.getText(); File someFile; FileOutputStream fos; int i=0; try { calc = (RecibirVideosRMI) Naming.lookup("rmi://" + host + "/consult"); } catch (Exception e) { JOptionPane.showMessageDialog(null, "Error: " + e.toString() + "\ni= "+i, "Mensaje", JOptionPane.INFORMATION_MESSAGE); } try { String ruta = txtRuta.getText(); if (txtIP.getText() != null) { byte[] video=calc.getVideo(file); if(video.length!=1 && video.length!=0){ someFile = new File(ruta + "\\" + file); fos = new FileOutputStream(someFile); fos.write(calc.getVideo(file)); fos.flush(); fos.close(); JOptionPane.showMessageDialog(null, "Encontrar su video en: " + ruta + "\\" + file, "Transferencia exitosa", JOptionPane.INFORMATION_MESSAGE); }else{ JOptionPane.showMessageDialog(null, "El servidor no esta aceptando peticiones en este momento.", "No se puede realizar la transferencia", JOptionPane.INFORMATION_MESSAGE); } } else { JOptionPane.showMessageDialog(null, "No ha ingresado el IP", "Error", JOptionPane.WARNING_MESSAGE); } } catch (IOException e) { if (e.getMessage() == null) { JOptionPane.showMessageDialog(null, "No existe la pelcula \"" + txtPedirPelicula.getText() + "\""+e.getMessage(), "Mensaje", JOptionPane.INFORMATION_MESSAGE); } else { System.out.println("Error: " + e.toString()); JOptionPane.showMessageDialog(null, "Error: " + e.toString(), "Mensaje", JOptionPane.INFORMATION_MESSAGE); } } } private void btnGuardarEnActionPerformed(java.awt.event.ActionEvent evt) { int retVal; JFileChooser chooser = new JFileChooser(); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); retVal = chooser.showOpenDialog(this); switch (retVal) { case (JFileChooser.APPROVE_OPTION):

9

txtRuta.setText(chooser.getSelectedFile().getAbsolutePath()); btnPedirPelicula.setEnabled(true); txtPedirPelicula.setEnabled(true); txtPedirPelicula.setText(""); break; case (JFileChooser.CANCEL_OPTION): chooser.setVisible(false); btnPedirPelicula.setEnabled(false); txtPedirPelicula.setEnabled(false); txtRuta.setText("Seleccione el directorio"); break; case (JFileChooser.ERROR_OPTION): txtRuta.setText("Error al seleccionar ruta"); } } private void formWindowOpened(java.awt.event.WindowEvent evt) { javax.swing.JOptionPane.showMessageDialog(this,"Bienvenidos a MalquiPeliculas RMI","MENSAJE",JOptionPane.INFORMATION_MESSAGE); }

public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new ClienteDePeliculas().setVisible(true); } }); } // Variables declaration - do not modify private javax.swing.JButton btnGuardarEn; private javax.swing.JButton btnMostrarPeliculas; private javax.swing.JButton btnPedirPelicula; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel4; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JTextArea jTextArea1; private javax.swing.JTextField jTextField1; private javax.swing.JTextField jTextField2; private javax.swing.JTextField txtIP; private javax.swing.JTextField txtPedirPelicula; private javax.swing.JTextField txtRuta; // End of variables declaration }

FORM ServidorVideospackage servidor; import java.net.*; import javax.swing.JFileChooser; import javax.swing.JOptionPane; import javax.swing.filechooser.FileNameExtensionFilter;

10

/** * * @author Anthony */ public class ServidorVideos extends javax.swing.JFrame { /** Creates new form ServidorVideos */ public ServidorVideos() { initComponents(); try { lblIP.setText(InetAddress.getLocalHost().getHostAddress()); } catch (UnknownHostException e) { lblIP.setText("Error al encontrar la ip local"); } try { servidor = new VideosRMIImpl("consult"); System.out.println("VideosRMI Server ready"); } catch (Exception e) { System.out.println("Error: "+e); } } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // private void initComponents() { jPanel1 = new javax.swing.JPanel(); jLabel1 = new javax.swing.JLabel(); txtRutaVideos = new javax.swing.JTextField(); btnRutaVideos = new javax.swing.JButton(); btnRutaCSV = new javax.swing.JButton(); txtRutaCSV = new javax.swing.JTextField(); jLabel4 = new javax.swing.JLabel(); jLabel3 = new javax.swing.JLabel(); lblIP = new javax.swing.JLabel(); jLabel5 = new javax.swing.JLabel(); jLabel6 = new javax.swing.JLabel(); txtPuertoDatos = new javax.swing.JTextField(); txtPuertoVideos = new javax.swing.JTextField(); btnDatos = new javax.swing.JButton(); btnVideos = new javax.swing.JButton(); jLabel7 = new javax.swing.JLabel(); jPanel2 = new javax.swing.JPanel(); jScrollPane1 = new javax.swing.JScrollPane(); taResultados = new javax.swing.JTextArea(); jLabel2 = new javax.swing.JLabel(); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); setTitle("Servidor de Videos"); addWindowListener(new java.awt.event.WindowAdapter() { public void windowOpened(java.awt.event.WindowEvent evt) { formWindowOpened(evt); } });

11

jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Archivos")); jLabel1.setText("Ubicacion de los videos"); txtRutaVideos.setText("Seleccione el directorio"); btnRutaVideos.setText("Cambiar"); btnRutaVideos.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnRutaVideosActionPerformed(evt); } }); btnRutaCSV.setText("Cambiar"); btnRutaCSV.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnRutaCSVActionPerformed(evt); } }); txtRutaCSV.setText("Seleccione el archivo CSV"); jLabel4.setText("Ubicacion del archivo *.csv"); javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); jPanel1.setLayout(jPanel1Layout); jPanel1Layout.setHorizontalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addContainerGap() .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 157, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(txtRutaCSV, javax.swing.GroupLayout.DEFAULT_SIZE, 283, Short.MAX_VALUE)) .addGap(6, 6, 6) .addComponent(btnRutaCSV)) .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE) .addGroup(jPanel1Layout.createSequentialGroup() .addComponent(txtRutaVideos, javax.swing.GroupLayout.DEFAULT_SIZE, 283, Short.MAX_VALUE) .addGap(6, 6, 6) .addComponent(btnRutaVideos))) .addContainerGap()) ); jPanel1Layout.setVerticalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addComponent(jLabel4) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(txtRutaCSV, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(btnRutaCSV)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(jLabel1) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)

12

.addComponent(txtRutaVideos, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(btnRutaVideos)) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); jLabel3.setText("IP Local"); jLabel5.setText("Puerto del servidor de datos"); jLabel6.setText("Puerto del servidor de videos"); txtPuertoDatos.setText("6000"); txtPuertoVideos.setText("6001"); btnDatos.setText("Iniciar"); btnDatos.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnDatosActionPerformed(evt); } }); btnVideos.setText("Iniciar"); btnVideos.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnVideosActionPerformed(evt); } }); jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Resultados")); jPanel2.setPreferredSize(new java.awt.Dimension(394, 137)); taResultados.setColumns(20); taResultados.setRows(5); jScrollPane1.setViewportView(taResultados); javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2); jPanel2.setLayout(jPanel2Layout); jPanel2Layout.setHorizontalGroup( jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel2Layout.createSequentialGroup() .addContainerGap() .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 362, Short.MAX_VALUE) .addContainerGap()) ); jPanel2Layout.setVerticalGroup( jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel2Layout.createSequentialGroup() .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(14, Short.MAX_VALUE)) ); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)

13

.addComponent(jPanel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup() .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(lblIP, javax.swing.GroupLayout.PREFERRED_SIZE, 148, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false) .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup() .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 172, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18) .addComponent(txtPuertoVideos)) .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup() .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 172, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18) .addComponent(txtPuertoDatos, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE))) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(btnVideos) .addGroup(layout.createSequentialGroup() .addComponent(btnDatos) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 43, Short.MAX_VALUE) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE))))) .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addContainerGap()) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(jLabel3) .addComponent(lblIP, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel7)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel5) .addComponent(txtPuertoDatos, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(btnDatos) .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)

14

.addComponent(jLabel6) .addComponent(txtPuertoVideos, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(btnVideos)) .addGap(18, 18, 18) .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); pack(); }// static String rutaCSV = "", rutaVideos = ""; static boolean servidorVideosActivo, servidorBDActivo; VideosRMIImpl servidor; private void btnRutaVideosActionPerformed(java.awt.event.ActionEvent evt) { int retVal; JFileChooser chooser = new JFileChooser(); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); retVal = chooser.showOpenDialog(this); switch (retVal) { case (JFileChooser.APPROVE_OPTION): rutaVideos=chooser.getSelectedFile().getAbsolutePath(); txtRutaVideos.setText(rutaVideos); servidor.setRutaVideos(rutaVideos); //btnVideos.setEnabled(true); break; case (JFileChooser.CANCEL_OPTION): txtRutaVideos.setText("Seleccione el directorio"); //btnVideos.setEnabled(false); break; case (JFileChooser.ERROR_OPTION): //btnVideos.setEnabled(false); txtRutaVideos.setText("Error al seleccionar ruta"); } } private void btnRutaCSVActionPerformed(java.awt.event.ActionEvent evt) { int retVal; JFileChooser chooser = new JFileChooser(); //chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); FileNameExtensionFilter filter = new FileNameExtensionFilter("Archivos CSV", "csv"); chooser.setFileFilter(filter); retVal = chooser.showOpenDialog(this); switch (retVal) { case (JFileChooser.APPROVE_OPTION): rutaCSV=chooser.getSelectedFile().getAbsolutePath(); txtRutaCSV.setText(rutaCSV); servidor.setRutaSCV(rutaCSV); //btnDatos.setEnabled(true); break; case (JFileChooser.CANCEL_OPTION): txtRutaCSV.setText("Seleccione el archivo CSV"); //btnDatos.setEnabled(false); break; case (JFileChooser.ERROR_OPTION): txtRutaCSV.setText("Error al seleccionar archivo");

15

//btnDatos.setEnabled(false); } } private void btnDatosActionPerformed(java.awt.event.ActionEvent evt) { rutaCSV = txtRutaCSV.getText(); if (servidorBDActivo) { servidorBDActivo = false; btnDatos.setText("Iniciar"); } else { servidorBDActivo = true; btnDatos.setText("Parar"); } servidor.setBDActivo(servidorBDActivo); } private void btnVideosActionPerformed(java.awt.event.ActionEvent evt) { rutaVideos = txtRutaVideos.getText() + "\\"; if (servidorVideosActivo) { servidorVideosActivo = false; btnVideos.setText("Iniciar"); } else { servidorVideosActivo = true; btnVideos.setText("Parar"); } servidor.setVideosActivo(servidorVideosActivo); } private void formWindowOpened(java.awt.event.WindowEvent evt) { javax.swing.JOptionPane.showMessageDialog(this,"BIENVENIDOS AL SERVIDOR DE PELICULAS Via RMI","MENSAJE",JOptionPane.INFORMATION_MESSAGE); } /** * @param args the command line arguments */ public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new ServidorVideos().setVisible(true); } }); } // Variables declaration - do not modify private javax.swing.JButton btnDatos; private javax.swing.JButton btnRutaCSV; private javax.swing.JButton btnRutaVideos; private javax.swing.JButton btnVideos; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel4; private javax.swing.JLabel jLabel5; private javax.swing.JLabel jLabel6; private javax.swing.JLabel jLabel7; private javax.swing.JPanel jPanel1; private javax.swing.JPanel jPanel2; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JLabel lblIP;

16

private javax.swing.JTextArea taResultados; private javax.swing.JTextField txtPuertoDatos; private javax.swing.JTextField txtPuertoVideos; private javax.swing.JTextField txtRutaCSV; private javax.swing.JTextField txtRutaVideos; // End of variables declaration }

1.- INICIAMOS NETBEANS Y ABRIMOS NUESTRO PROYECTO

17

2.- VAMOS A LA DIRECCION C:\Program Files\Java\jdk1.6.0_18\bin , COPIAMOS LOS ARCHIVOS jli.dll Y rmiregistry.exe A LA SIGUIENTE DIRECCION: G:\Redes 2\Proyecto RMI\Programa\ PeliculasViaRMI\ build\classes

3.- HACEMOS DOBLE CLICK EN EL ARCHIVO rmiregistry.exe Y LO DEJAMOS ABIERTO

18

4.- LUEGO VAMOS AL NETBEANS Y COMPILAMOS EL FORMULARIO ClienteDePeliculas Y NOS SALDRA UN MENSAJE DE BIENVENIDA

5.- LUEGO VAMOS AL NETBEANS Y COMPILAMOS EL FORMULARIO ServidorVideos Y NOS SALDRA UN MENSAJE DE BIENVENIDA

19

6.- LUEGO DEBEMOS TENER LOS DOS FORMULARIOS Y EL rmiregistry.exe ABIERTO

20

7.- EN EL FORMULARIO ServidorVideos LLENAMOS LA UBICACIN DE LA BASE DE DATOS Y LA DE LOS VIDEOS. ACEPTAMOS LA DIRECCION DEL SERVIDOR DE VIDEOS Y LA DE LA BASE DE DATOS.

8.- EN EL FORMULARIO Cliente HACEMOS CLICK EN EL BOTON MOSTRAR PELICULAS Y APARECERAN LOS DATOS DE LAS PELICULAS Y EL BOTON GUARDAR AQUI SE HABILITARA.

9.- LUEGO PRESIONAMOS EL BOTON GUARDAR AQUI Y ELEGIREMOS LA DIRECCION EN DONDE ENVIAREMOS EL VIDEO Y AUTOMATICAMENTE SE HABILITARA EL BOTON NOMBRE DEL VIDEO.21

10.- LLENAREMOS CON EL NOMBRE DEL VIDEO QUE QUERAMOS ENVIAR A OTRA DIRECCION, PRESIONAMOS NOMBRE DEL VIDEO Y SALDRA EL SIGUIENTE MENSAJE.

11.- ENCONTRAREMOS EL VIDEO EN LA NUEVA DIRECCION.

22