0% encontró este documento útil (0 votos)
94 vistas8 páginas

Actividad de Aprendizaje 4 Sistemas Distribuidos

Este documento presenta el código Java para una aplicación de calculadora distribuida utilizando RMI. Se definen tres clases: Calculadora (interfaz), RMI (implementa la lógica de negocio remota), y Servidor y Cliente (implementan el servidor y cliente). El servidor inicia el registro RMI y el cliente realiza las operaciones solicitando al objeto remoto y mostrando los resultados.
Derechos de autor
© © All Rights Reserved
Nos tomamos en serio los derechos de los contenidos. Si sospechas que se trata de tu contenido, reclámalo aquí.
Formatos disponibles
Descarga como PDF, TXT o lee en línea desde Scribd
0% encontró este documento útil (0 votos)
94 vistas8 páginas

Actividad de Aprendizaje 4 Sistemas Distribuidos

Este documento presenta el código Java para una aplicación de calculadora distribuida utilizando RMI. Se definen tres clases: Calculadora (interfaz), RMI (implementa la lógica de negocio remota), y Servidor y Cliente (implementan el servidor y cliente). El servidor inicia el registro RMI y el cliente realiza las operaciones solicitando al objeto remoto y mostrando los resultados.
Derechos de autor
© © All Rights Reserved
Nos tomamos en serio los derechos de los contenidos. Si sospechas que se trata de tu contenido, reclámalo aquí.
Formatos disponibles
Descarga como PDF, TXT o lee en línea desde Scribd
Está en la página 1/ 8

ACTIVIDAD DE APRENDIZAJE 4

SISTEMAS DISTRIBUIDOS

Andrés Yowani Amado Reyes

Marzo de 2022

Unipanamericana
TECNOLOGÍA EN ANÁLISIS Y DESARROLLO DE SISTEMAS DE INFORMACIÓN
SISTEMAS DISTRIBUIDOS

1
ACTIVIDAD DE APRENDIZAJE 4
SISTEMAS DISTRIBUIDOS

Andrés Yowani Amado Reyes

Marzo de 2022

Unipanamericana
TECNOLOGÍA EN ANÁLISIS Y DESARROLLO DE SISTEMAS DE INFORMACIÓN
SISTEMAS DISTRIBUIDOS
Bogotá, Colombia

2
Contenido
ACTIVIDAD .........................................................................................................................................4
Solución .............................................................................................................................................4
Código Java ........................................................................................................................................4
Interfaz Calculadora.java ...................................................................................................................4
Clase RMI. Java .................................................................................................................................5
Clase Servidor. Java ...........................................................................................................................5
Clase Cliente. Java .............................................................................................................................6
Link del Video Explicativo ..................................................................................................................8

3
ACTIVIDAD

Comparta en esta tarea un link a un video propio, demostrando el funcionamiento de programa


completo y como fue programado una aplicación tipo calculadora programada en Java y
empleando RMI. Condiciones básicas para el desarrollo de la actividad: diseñar una calculadora,
que obtenga los datos a nivel local (operando A, operando B y tipo de operación) en el cliente,
este a su vez solicitara al servidor la realización de la operación correspondiente. Para interactuar
con este tipo de "objetos remotos", se requiere en java, programar tres clases diferentes (cliente,
servidor e interface), la interface será el traductor y el "esqueleto" del objeto a crear. Como
evidencia de esta actividad, se deberá realizar un video demostrando el funcionamiento del
programa completo y como fue programado.

Solución

Código Java
Interfaz Calculadora.java
package AA4_Calculatore;

import java.rmi.Remote;
import java.rmi.RemoteException;

public interface Calculadora extends Remote{


public int div(int a, int b)throws
RemoteException;
public int mul(int a, int b)throws
RemoteException;
public int res(int a, int b)throws
RemoteException;
public int sum(int a, int b)throws
RemoteException;
}

4
Clase RMI. Java
package AA4_Calculatore;
import java.rmi.server.UnicastRemoteObject;
import java.rmi.RemoteException;

public class RMI extends UnicastRemoteObject implements


Calculadora{
public RMI() throws RemoteException{
int a,b;
}

public int div(int a, int b)throws RemoteException{


return a / b;
}
public int mul(int a, int b)throws RemoteException{
return a * b;
}
public int res(int a, int b)throws RemoteException{
return a - b;
}
public int sum(int a, int b)throws RemoteException{
return a + b;
}
}

Clase Servidor. Java


package AA4_Calculatore;
import java.rmi.registry.Registry;
import javax.swing.JOptionPane;

public class Servidor {


public static void main(String[] args){
try{
Registry r =
java.rmi.registry.LocateRegistry.createRegistry(1090);
r.rebind("Calculadora", new RMI());
JOptionPane.showMessageDialog(null, "Servidor
Conectado");
}
catch(Exception e){
JOptionPane.showMessageDialog(null, "Servidor
Desconectado" + e);
}
}
}

5
Clase Cliente. Java
package AA4_Calculatore;
import java.rmi.Naming;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.util.Scanner;
import javax.swing.JOptionPane;

public class Cliente {

public static void main(String[] args){


Scanner sc = new Scanner(System.in);
try{
Registry registro = LocateRegistry.getRegistry("localhost",
1090);
Calculadora c =
(Calculadora)Naming.lookup("//localhost/Calculadora");
while(true){
String menu = JOptionPane.showInputDialog("
Calculadora \n **Sistemas Distribuidos**\n\n"
+"1.Suma \n"
+"2.Resta \n"
+"3.División \n"
+"4.Multiplicacion \n"
+"Esc.Exist\n\n");
switch(menu){
case "1":{
int x =

6
Integer.parseInt(JOptionPane.showInputDialog("Ingrese el Primer
Numero"));
int y =
Integer.parseInt(JOptionPane.showInputDialog("Ingrese el
Segundo Numero"));

JOptionPane.showMessageDialog(null, "Sumo:\n"+ x +"


mas "+ y + "\nY el resultado de la operación es: \n" +
c.sum(x,y)+"\n"+"Operación:\n"+ x +" + "+ y + " = " + c.sum(x,y));
break;
}
case "2":{
int x =
Integer.parseInt(JOptionPane.showInputDialog("Ingrese el Primer
Numero"));
int y =
Integer.parseInt(JOptionPane.showInputDialog("Ingrese el
Segundo Numero"));

JOptionPane.showMessageDialog(null,"Resto:\n"+ x +"
menos "+ y + "\nY el resultado de la operación es: \n" +
c.res(x,y)+"\n"+"Operación:\n"+ x +" - "+ y + " = " + c.res(x,y));
break;
}
case "3":{
int x =
Integer.parseInt(JOptionPane.showInputDialog("Ingrese el Primer
Numero"));
int y =
Integer.parseInt(JOptionPane.showInputDialog("Ingrese el
Segundo Numero"));

JOptionPane.showMessageDialog(null, "Dividio:\n"+ x +"


en "+ y + "\nY el resultado de la operación es: \n" +
c.div(x,y)+"\n"+"Operación:\n"+ x +" ÷ "+ y + " = " + c.div(x,y));
break;
}
case "4":{
int x =
Integer.parseInt(JOptionPane.showInputDialog("Ingrese el Primer
Numero"));
int y =
Integer.parseInt(JOptionPane.showInputDialog("Ingrese el

7
Segundo Numero"));

JOptionPane.showMessageDialog(null, "Multiplico:\n"+
x +" por "+ y + "\nY el resultado de la operación es: \n" +
c.mul(x,y)+"\n"+"Operación:\n"+ x +" X "+ y + " = " + c.mul(x,y));
break;
}
}
}
}catch(Exception e){
JOptionPane.showMessageDialog(null,"Servidor no
conectado"+e);
}
}
}

Link del Video Explicativo

https://youtu.be/S937Ow4GX4k

También podría gustarte