Bonsoir,
je travaille sur un projet mettant en oeuvre un serveur et une interface graphique distante communicants par RMI. Tout le développement de ce projet a été fait sous XP, et lorsque j'ai essayé de le lancer sous linux (fedora 11) une exception bizarre a été levée lors de la tentative de connexion au serveur
re test avec une serveur tout simple et pareil pour client :
ServeurRMI.java
Client.java:
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
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59 import java.rmi.*; import java.rmi.server.*; public class ServeurRMI extends UnicastRemoteObject implements Serveur_interface { /** * */ private static final long serialVersionUID = -463203912015592773L; protected ServeurRMI() throws RemoteException { super(); } public String getInformation()throws RemoteException { return "bonjour"; } public static void main(String[] args) { try { java.rmi.registry.LocateRegistry.createRegistry(55555); //System.out.println("Mise en place du Security Manager ..."); //System.setSecurityManager(new java.rmi.RMISecurityManager()); ServeurRMI serveurRMI = new ServeurRMI(); System.out.println("Enregistrement du serveur"); Naming.bind("rmi://127.0.0.1:55555/TestRMI",serveurRMI); System.out.println("Serveur lancé"); } catch (Exception e) { System.out.println("Exception capturée: " + e.getMessage()); } } }(vraiment rien de compliqué !)
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 import java.rmi.*; public class Client implements Remote{ public static Remote r; public static void main(String[] args) throws Exception { //System.setSecurityManager(new RMISecurityManager()); r = Naming.lookup("rmi://127.0.0.1:55555/TestRMI"); if (r instanceof Serveur_interface) { String s = ((Serveur_interface) r).getInformation(); System.out.println("chaine renvoyée = " + s); } } }
même exception :
:étant en réseau local, avec adressage en 192.168.1.x, l'adresse IP 0.0.6.15 m'a frappé ! pareil si je mets mon nom réseau à la place de l'adresse IP !
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
24 Exception in thread "main" java.rmi.ConnectIOException: Exception creating connection to: 0.0.6.155; nested exception is: java.net.SocketException: Invalid argument or cannot assign requested address at sun.rmi.transport.tcp.TCPEndpoint.newSocket(Unknown Source) at sun.rmi.transport.tcp.TCPChannel.createConnection(Unknown Source) at sun.rmi.transport.tcp.TCPChannel.newConnection(Unknown Source) at sun.rmi.server.UnicastRef.invoke(Unknown Source) at java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(Unknown Source) at java.rmi.server.RemoteObjectInvocationHandler.invoke(Unknown Source) at $Proxy0.getInformation(Unknown Source) at Client.main(Client.java:11) Caused by: java.net.SocketException: Invalid argument or cannot assign requested address at java.net.PlainSocketImpl.socketConnect(Native Method) at java.net.PlainSocketImpl.doConnect(Unknown Source) at java.net.PlainSocketImpl.connectToAddress(Unknown Source) at java.net.PlainSocketImpl.connect(Unknown Source) at java.net.SocksSocketImpl.connect(Unknown Source) at java.net.Socket.connect(Unknown Source) at java.net.Socket.connect(Unknown Source) at java.net.Socket.<init>(Unknown Source) at java.net.Socket.<init>(Unknown Source) at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(Unknown Source) at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(Unknown Source) ... 8 more
quand j'essaye une autre adresse IP dans le code, il me dit qu'il ne trouve pas l'hôte ou que la connexion n'a pas pu être établie...
Les deux projets fonctionnent sous XP sans aucun souci,
mon fichier /etc/hosts
je ne sais pas où chercher (surtout avec cette IP 0.0.6.155)
Code : Sélectionner tout - Visualiser dans une fenêtre à part 127.0.0.1 localhost.localdomain localhost
Merci pour tout renseignement utile !
Partager