Praktikum kali ini kita akan membahas mengenai aplikasi sayhello berbasis client server dengan menggunakan java berikut coding nya
- coding pada server
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.echo.clientserver.sayhello.server;
import com.echo.clientserver.sayhello.SayHello;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
/**
*
* @author UNLA
*/
public class SayHelloServer extends UnicastRemoteObject implements SayHello{
public SayHelloServer() throws RemoteException {
}
public String sayHello (String nama) throws RemoteException {
System.out.println ("Client Dengan nama " + nama + " Melakukan Request Loh");
return "Hello " + nama;
}
}
------------------------------------------------------------------------------------------------------------
main.java
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.echo.clientserver.sayhello.server;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
/**
*
* @author UNLA
*/
public class main {
public static void main(String[] args) throws RemoteException {
Registry registry = LocateRegistry.createRegistry (1099);
SayHelloServer sayHello = new SayHelloServer();
registry.rebind ("sayHello", sayHello);
System.out.println ( " Server telah Berjalan ");
// TODO code application logic here
}
}
------------------------------------------------------------------------------------------------------------
- coding pada client
main.java
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.echo.clientserver.sayhello.server;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
/**
*
* @author UNLA
*/
public class main {
public static void main(String[] args) throws RemoteException {
Registry registry = LocateRegistry.createRegistry (1099);
SayHelloServer sayHello = new SayHelloServer();
registry.rebind ("sayHello", sayHello);
System.out.println ( " Server telah Berjalan ");
// TODO code application logic here
}
}
------------------------------------------------------------------------------------------------------------
- coding pada api.java nya:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.echo.clientserver.sayhello;
import java.rmi.Remote;
import java.rmi.RemoteException;
/**
*
* @author UNLA
*/
public interface SayHello extends Remote {
public String sayHello (String nama) throws RemoteException;
}
berikut tampilan ketika server telah dijalankan :