Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Last active February 12, 2018 16:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/3ca2742af080ea70e1d4129c4ff0cff6 to your computer and use it in GitHub Desktop.
Save parzibyte/3ca2742af080ea70e1d4129c4ff0cff6 to your computer and use it in GitHub Desktop.
import java.rmi.AlreadyBoundException;
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;
public class Servidor {
private static final int PUERTO = 1100; //Si cambias aquí el puerto, recuerda cambiarlo en el cliente
public static void main(String[] args) throws RemoteException, AlreadyBoundException {
Remote remote = UnicastRemoteObject.exportObject(new Interfaz() {
/*
Sobrescribir opcionalmente los métodos que escribimos en la interfaz
*/
@Override
public float sumar(float numero1, float numero2) throws RemoteException {
return numero1 + numero2;
};
@Override
public float restar(float numero1, float numero2) throws RemoteException {
return numero1 - numero2;
};
@Override
public float multiplicar(float numero1, float numero2) throws RemoteException {
return numero1 * numero2;
};
@Override
public float dividir(float numero1, float numero2) throws RemoteException {
return numero1 / numero2;
};
}, 0);
Registry registry = LocateRegistry.createRegistry(PUERTO);
System.out.println("Servidor escuchando en el puerto " + String.valueOf(PUERTO));
registry.bind("Calculadora", remote); // Registrar calculadora
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment