Bonjour,
j'ai un petit problème avec RMI :

j'ai deux packages client et server,



le package client contient une interface "I_object" :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
package client;
 
import java.rmi.Remote;
import java.rmi.RemoteException;
 
public interface I_object extends Remote {  
    public int Add(int a,int b) throws RemoteException;
}

et une class main_client :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
package client;
import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
 
/**
 *
 * @author marwen
 */
public class main_client {
 
 
    public static void main(String [] args) throws NotBoundException, MalformedURLException, RemoteException{
 
     I_object obj_distant=(I_object) Naming.lookup("rmi://localhost:1000/exemple");
 
     System.out.println(obj_distant.Add(5, 9));    
 
    }
}

pour le package server j'ai une implementation de l'interface I_object, impl_object:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
 
package server;
 
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
 
 
/**
 *
 * @author marwen
 */
public class impl_object  extends UnicastRemoteObject implements I_object {
 
    public impl_object() throws RemoteException
    {}
 
    public int Add(int a,int b) throws RemoteException{
    return a+b;
    }
 
}


et enfin un main_server :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
package server;
 
import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
 
/**
 *
 * @author marwen
 */
public class main_server {
 
    public static void main(String [] args) throws NotBoundException, MalformedURLException, RemoteException{
        impl_object obj=new impl_object();
 
       java.rmi.registry.LocateRegistry.createRegistry(1000);
 
       Naming.rebind("rmi://localhost:1000/exemple", obj);
 
    System.out.println("server is running");
    }
}


Mon problème ce n'est pas avec le code , mais plutot avec l'interface "I_object" , si vous avez remarqué dans l’implémentation de cette interface , "impl_object " j'ai pas mis un "import client.I_object;" pourquoi ??
justement si je met un import vers le package client , le server donc sera "lié" a ce client(cad on doit mettre toujours le package client pré le package server pour que le server puisse connaitre la structure de I_object...)
MAIS lorsque je sépare le client et le server (je met le server sur un ordinateur distant et le client chez moi ) ????
PAR CONTRE si je met "import client.I_object;" dans impl_object ça marche trés bien....
voila quelqu'un peut m'expliquer , j'ai tort ?

Merci