Witam ponownie :)
trzy kody, wyklepane na szybko dla testu:
interface:
import java.rmi.*;
public interface ss extends Remote{
public int Sum(int a, int b) throws Exception;
}
impl+server
import java.net.MalformedURLException;
import java.rmi.*;
import java.rmi.server.*;
import java.rmi.registry.*;
import java.util.logging.Level;
import java.util.logging.Logger;
public class ssimpl extends UnicastRemoteObject implements ss{
ssimpl() throws RemoteException{
super();
}
public int Sum(int a,int b) throws RemoteException{
return a+b;
}
public static void main(String [] args){
try{
ssimpl server =new ssimpl();
Naming.rebind("sample", server);
System.out.println("Server is listening");
}
catch (MalformedURLException ex) {
Logger.getLogger(ssimpl.class.getName()).log(Level.SEVERE, null, ex);
} catch (RemoteException e){
System.out.println("error" + e);
}
}
}
cli:
import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
public class sc {
public static void main(String[] args) throws NotBoundException, MalformedURLException, Exception{
try{
String URL="//localhost/ss";
ss RemoteObject =(ss)Naming.lookup(URL);
System.out.println("got obj");
System.out.println("1+2" + RemoteObject.Sum(1,2));
}
catch(RemoteException e){
System.out.println("error "+ e);
}
}
}
i niby wszystko cacy, najpierw rmiregistry, potem rmic ssimpl, potem odpalam kulturalnie server, server słucha, no i klient się wywala z błędem takim:
Exception in thread "main" java.rmi.NotBoundException: ss
at sun.rmi.registry.RegistryImpl.lookup(RegistryImpl.java:106)
at sun.rmi.registry.RegistryImpl_Skel.dispatch(Unknown Source)
at sun.rmi.server.UnicastServerRef.oldDispatch(UnicastServerRef.java:386
)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:250)
at sun.rmi.transport.Transport$1.run(Transport.java:159)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:155)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:5
35)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTranspor
t.java:790)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport
.java:649)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExec
utor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor
.java:908)
at java.lang.Thread.run(Thread.java:619)
at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(Stream
RemoteCall.java:255)
at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:
233)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:359)
at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
at java.rmi.Naming.lookup(Naming.java:84)
at sc.main(sc.java:20)
problem występuje przy każdym programie typu klient wykorzystującym remote methods.