Hallo Leute!
ich habe ein rmi Beispiel erfolgreich ausgeführt (Seihe Code unten). Aber ich moechte auch mein Client (AdderClient.java) als Server benutzen (d.h. AdderImpl.java und AdderClient.java sind jeweils Server und Client gleichtzeitig). Ist das überhaupt möglich? Wenn ja bitte wie.
Vielen Dank im Vorraus :wink:
Schöne Grüsse
ich habe ein rmi Beispiel erfolgreich ausgeführt (Seihe Code unten). Aber ich moechte auch mein Client (AdderClient.java) als Server benutzen (d.h. AdderImpl.java und AdderClient.java sind jeweils Server und Client gleichtzeitig). Ist das überhaupt möglich? Wenn ja bitte wie.
Vielen Dank im Vorraus :wink:
Schöne Grüsse
Code:
// AdderClient.java (Client)
import java.rmi.Naming;
public class AdderClient
{
public static void main( String args[] ) throws Exception
{
Adder a = (Adder) Naming.lookup( "rmi://129.187.51.223/adder" );
int sum = a.add( 88, 9);
System.out.println( sum );
}
}
// AdderImpl.java (Server)
import java.rmi.Naming;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
public class AdderImpl extends UnicastRemoteObject implements Adder
{
public AdderImpl() throws RemoteException
{
}
public int add( int x, int y ) throws RemoteException
{
return (x +y);
}
public static void main( String args[] ) throws Exception
{
Naming.rebind( "rmi://localhost/adder", new AdderImpl() );
System.out.println( "Adder bound" );
}
}
// Adder.java
import java.rmi.Remote;
import java.rmi.RemoteException;
public interface Adder extends Remote {
public int add( int x, int y ) throws RemoteException;
}