probléme avec Rmi besoin d'aide
Salut
j'utilise le concept Rmi pour mon projet , mon code fonctionne correctement en localhost mais quand j'essaie sur mon réseau local ça marche pas ça donne les exceptions suivante :
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 30
| java.rmi.ConnectException: Connection refused to host: localhost; nested excepti
on is:
java.net.ConnectException: Connection refused: connect
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:601)
at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:198
)
at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:184)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:110)
at java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(Remo
teObjectInvocationHandler.java:178)
at java.rmi.server.RemoteObjectInvocationHandler.invoke(RemoteObjectInvo
cationHandler.java:132)
at $Proxy0.somme(Unknown Source)
at CliSom.main(CliSom.java:21)
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:525)
at java.net.Socket.connect(Socket.java:475)
at java.net.Socket.<init>(Socket.java:372)
at java.net.Socket.<init>(Socket.java:186)
at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirect
SocketFactory.java:22)
at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(RMIMaster
SocketFactory.java:128)
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:595)
... 7 more |
c'est juste un petite application pour faire une somme de 2 entiers :
mon code :
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 30 31 32 33 34 35 36 37 38 39 40 41 42
| import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;
import java.util.logging.Level;
import java.util.logging.Logger;
public class ServSom implements Sommer {
public ServSom() throws RemoteException
{
super();
}
public static void main(String[] args) {
if(System.getSecurityManager()==null)
{
System.setSecurityManager(new SecurityManager());
}
try {
Sommer servSom = new ServSom();
// System.setProperty("java.security.policy", "c:\\policef");
Sommer stub =(Sommer) UnicastRemoteObject.exportObject(servSom,0);
Registry registry = LocateRegistry.getRegistry();
registry.rebind("somme2",stub);
System.out.println("serveur en route");
} catch (Exception ex) {
Logger.getLogger(ServSom.class.getName()).log(Level.SEVERE, null, ex);
}
}
public int somme(int a, int b) throws RemoteException {
return a+b;
}
} |
Interface:
Citation:
import java.rmi.Remote;
import java.rmi.RemoteException;
public interface Sommer extends Remote {
public int somme(int a,int b ) throws RemoteException;
}
Client :
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
| import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.util.logging.Level;
import java.util.logging.Logger;
public class CliSom {
public static void main(String args[])
{
try {
String name = "somme2";
Registry registry = LocateRegistry.getRegistry(args[0]);
Sommer somm =(Sommer) registry.lookup(name);
int i = somm.somme(Integer.parseInt(args[1]),Integer.parseInt(args[2]));
System.out.println("la somme est :"+i);
} catch (Exception ex) {
Logger.getLogger(CliSom.class.getName()).log(Level.SEVERE, null, ex);
}
}
} |
Svp aidez moi avec ce probléme