Last active
February 12, 2018 16:15
-
-
Save parzibyte/3ca2742af080ea70e1d4129c4ff0cff6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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