Commit 49a4910c by Charno Simanjuntak

Calculator server client

parents
Cara menjalankannya kan teman Sistem Informasi kek gini :
1. buka file Calculator , trus bukalah cmd kan , baru ketik "start rmiregistry"
2. buka file server , trus buka cmd, baru ketik "start java -classpath . -Djava.rmi.server.codebase=file:./ CalcServer localhost
2002"
3. buka file client, trus buka cmd, baru ketik "java -classpath . calc localhost 2002 tambah 1000 3000"
untuk operasi kurang, , kali, bagi, modulo, pangkat, udah bisa juga. tinggal mengganti di java -clashpath . calc localhost 2002 GANTI 1000 3000
NOTE : jalankan dlu rmiregistry, baru jalankan server dan client :)
Maaf ya teman, cuma ini masih yang bisa ku bantu.
\ No newline at end of file
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
public class Calc {
public static void main(String args[]){
String host = (args.length < 1) ? "localhost" : args[0];
String port = (args.length < 2) ? "1099" : args[1];
try {
Registry registry = LocateRegistry.getRegistry(host,Integer.parseInt(port));
Operasi operasi = (Operasi) registry.lookup("operasi");
Double hasil = 0.0;
switch(args[2]){
case "tambah":
hasil = operasi.tambah(Double.parseDouble(args[3]),Double.parseDouble(args[4]));
break;
case "kurang":
hasil = operasi.kurang(Double.parseDouble(args[3]),Double.parseDouble(args[4]));
break;
case "kali":
hasil = operasi.kali(Double.parseDouble(args[3]),Double.parseDouble(args[4]));
break;
case "bagi":
hasil = operasi.bagi(Double.parseDouble(args[3]),Double.parseDouble(args[4]));
break;
case "modulo":
hasil = operasi.modulo(Double.parseDouble(args[3]),Double.parseDouble(args[4]));
break;
case "pangkat":
hasil = operasi.pangkat(Double.parseDouble(args[3]),Double.parseDouble(args[4]));
break;
default:
System.out.println("Operasi tidak dikenali atau parameter tidak lengkap");
break;
}
System.out.println("Hasil: " + hasil);
} catch (Exception e) {
System.out.println("Calc exception: " + e.getMessage());
e.printStackTrace();
}
}
}
\ No newline at end of file
import java.rmi.registry.Registry;
import java.rmi.registry.LocateRegistry;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
public class CalcServer implements Operasi
{
public CalcServer() throws RemoteException {}
public Double tambah(Double x, Double y) {
return x + y;
}
public Double kurang(Double x, Double y){
return x - y;
}
public Double kali(Double x, Double y){
return x * y;
}
public Double bagi(Double x, Double y){
return x / y;
}
public Double modulo(Double x, Double y){
return x % y;
}
public Double pangkat(Double x, Double y){
return Math.pow(x,y);
}
public static void main (String args[]){
String host = (args.length < 1) ? "localhost" : args[0];
String port = (args.length < 2) ? "1099" : args[1];
try{
CalcServer remoteObject = new CalcServer();
Operasi skeleton = (Operasi)UnicastRemoteObject.exportObject(remoteObject, 0);
Registry registry = LocateRegistry.getRegistry(host,Integer.parseInt(port));
registry.rebind("operasi", skeleton);
System.out.println("Server Ready !!");
}catch (Exception e) {
System.out.println("HelloServer Err: " + e.getMessage());
e.printStackTrace();
}
}
}
\ No newline at end of file
//Operasi.java
import java.rmi.Remote;
import java.rmi.RemoteException;
public interface Operasi extends Remote
{
Double tambah(Double x, Double y) throws RemoteException;
Double kurang(Double x, Double y) throws RemoteException;
Double kali(Double x, Double y) throws RemoteException;
Double bagi(Double x, Double y) throws RemoteException;
Double modulo(Double x, Double y) throws RemoteException;
Double pangkat(Double x, Double y) throws RemoteException;
}
\ No newline at end of file
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
public class Calc {
public static void main(String args[]){
String host = (args.length < 1) ? "localhost" : args[0];
String port = (args.length < 2) ? "1099" : args[1];
try {
Registry registry = LocateRegistry.getRegistry(host,Integer.parseInt(port));
Operasi operasi = (Operasi) registry.lookup("operasi");
Double hasil = 0.0;
switch(args[2]){
case "tambah":
hasil = operasi.tambah(Double.parseDouble(args[3]),Double.parseDouble(args[4]));
break;
case "kurang":
hasil = operasi.kurang(Double.parseDouble(args[3]),Double.parseDouble(args[4]));
break;
case "kali":
hasil = operasi.kali(Double.parseDouble(args[3]),Double.parseDouble(args[4]));
break;
case "bagi":
hasil = operasi.bagi(Double.parseDouble(args[3]),Double.parseDouble(args[4]));
break;
case "modulo":
hasil = operasi.modulo(Double.parseDouble(args[3]),Double.parseDouble(args[4]));
break;
case "pangkat":
hasil = operasi.pangkat(Double.parseDouble(args[3]),Double.parseDouble(args[4]));
break;
default:
System.out.println("Operasi tidak dikenali atau parameter tidak lengkap");
break;
}
System.out.println("Hasil: " + hasil);
} catch (Exception e) {
System.out.println("Calc exception: " + e.getMessage());
e.printStackTrace();
}
}
}
\ No newline at end of file
//Operasi.java
import java.rmi.Remote;
import java.rmi.RemoteException;
public interface Operasi extends Remote
{
Double tambah(Double x, Double y) throws RemoteException;
Double kurang(Double x, Double y) throws RemoteException;
Double kali(Double x, Double y) throws RemoteException;
Double bagi(Double x, Double y) throws RemoteException;
Double modulo(Double x, Double y) throws RemoteException;
Double pangkat(Double x, Double y) throws RemoteException;
}
\ No newline at end of file
import java.rmi.registry.Registry;
import java.rmi.registry.LocateRegistry;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
public class CalcServer implements Operasi
{
public CalcServer() throws RemoteException {}
public Double tambah(Double x, Double y) {
return x + y;
}
public Double kurang(Double x, Double y){
return x - y;
}
public Double kali(Double x, Double y){
return x * y;
}
public Double bagi(Double x, Double y){
return x / y;
}
public Double modulo(Double x, Double y){
return x % y;
}
public Double pangkat(Double x, Double y){
return Math.pow(x,y);
}
public static void main (String args[]){
String host = (args.length < 1) ? "localhost" : args[0];
String port = (args.length < 2) ? "1099" : args[1];
try{
CalcServer remoteObject = new CalcServer();
Operasi skeleton = (Operasi)UnicastRemoteObject.exportObject(remoteObject, 0);
Registry registry = LocateRegistry.getRegistry(host,Integer.parseInt(port));
registry.rebind("operasi", skeleton);
System.out.println("Server Ready !!");
}catch (Exception e) {
System.out.println("HelloServer Err: " + e.getMessage());
e.printStackTrace();
}
}
}
\ No newline at end of file
//Operasi.java
import java.rmi.Remote;
import java.rmi.RemoteException;
public interface Operasi extends Remote
{
Double tambah(Double x, Double y) throws RemoteException;
Double kurang(Double x, Double y) throws RemoteException;
Double kali(Double x, Double y) throws RemoteException;
Double bagi(Double x, Double y) throws RemoteException;
Double modulo(Double x, Double y) throws RemoteException;
Double pangkat(Double x, Double y) throws RemoteException;
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment