Aplikasi Client Server Java - Praktikum 2
Pada kali ini saya akan mencoba menampilkan beberapa Source Code bagaimana interaksi server ke client atau sebaliknya .
Source Code 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
}
}
------------------------------------------------------------------------------------------------------------
· Source Code 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
}
}
------------------------------------------------------------------------------------------------------------
· Source Code 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 :
Tidak ada komentar:
Posting Komentar