Problème Client Serveur RMI
Bonjour,
Dans le cadre d'un projet j'ai utiliser l'application RMI de java sous netbeans.
Ma comunication RMI fonctione sans problème J'arrive a appeler le méthode exporter par le serveur depui le client. Mon problème c'est que je n'arrive pas a trouver comment faire pour permettre au serveur d'appeler des methodes du d'une classe situer sur le client.
voila mon code
Fichier qui lance le RMI du serveur
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| try {
try {
reg=LocateRegistry.createRegistry(Integer.parseInt(por));
} catch (Exception e) {
System.out.println("Erreur 2");
}
if (System.getSecurityManager() == null) {
System.setSecurityManager(new RMISecurityManager());
}
mapartie = new mon_objet_distant();
try {
try {
Naming.rebind("//127.0.0.1:" + por + "/mon_interface_jeux",mapartie);
} catch (MalformedURLException ex) {
}
} catch (RemoteException ex) {
}
System.out.println("enregistrement du serveur "+por+" ok");
} catch (RemoteException ex) {
} |
Interface Serveur pour le client
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| package Serveur_pong;
/**
*
* @author revan
*/
import java.rmi.*;
public interface mon_interface_jeux extends java.rmi.Remote {
public void set_move(int nbc, int n)throws RemoteException;
public void set_taille_c(int nbc, int n)throws RemoteException;
// etc...
} |
fichier qui implémente l'interface sur le serveur
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| public class mon_objet_distant extends java.rmi.server.UnicastRemoteObject
implements mon_interface_jeux, ActionListener {
//attribut
private Timer tm_deplace=null;
//etc...
mon_objet_distant() throws RemoteException{
pas_ball=10;
dir_ball=-Math.PI/6;
//etc...
}
public int get_taille_c(int nbc)
{
return info_joueur[nbc][3];
}
public int get_pos_c(int nbc)
{
return info_joueur[nbc][2];
}
// etc...
} |
Et enfin le fichier du client
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
public class monjeux extends javax.swing.JFrame implements ActionListener {
//attribut
private Serveur_pong.mon_interface_jeux jeux=null;
public monjeux(String nom,String port) throws RemoteException {
initComponents();
try {
jeux = (Serveur_pong.mon_interface_jeux)Naming.lookup("rmi://127.0.0.1:"+port+"/mon_interface_jeux");
} catch (NotBoundException ex) {
JOptionPane.showMessageDialog(null,ex.toString()+" erreur 1");
} catch (MalformedURLException ex) {
JOptionPane.showMessageDialog(null,ex.toString()+" erreur 2");
} catch (RemoteException ex) {
JOptionPane.showMessageDialog(null,ex.toString()+" erreur 3");
}
} |
Donc tout ceci marche sans problème mais j'aimerais maintenant que le serveur puisse appeler des methodes du client, donc faire comme une double communication mais je vois pas comment faire en évitant que le client soit serveur? si quelqu'un peut m'aidé ca serai super gentil ^^