Donc c'est clairement un problème de timeout trop long. Voir mon post précédent.
Version imprimable
Donc c'est clairement un problème de timeout trop long. Voir mon post précédent.
J'ai changé le timeout mais rien ne s'est passé!!
as tu bien compilé et mis sur le servuer le code modifié? Parce qu'il n'y a pas de raison que le timeout ne sois pas respecté. On peux voir le code modifié?
Voilà la classe PScanner que j'ai modifiée:
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
26package servers; import java.net.*; import java.io.IOException; public class PScanner { public static int scan( InetAddress remote,int port) { int b=1; //int port; String hostname = remote.getHostName(); try { Socket s1 = new Socket(); s1.bind(null); s1.connect(new InetSocketAddress(hostname,port), 500); b=1; s1.close(); } catch (IOException ex) { b=0; } return b; } }
peux tu modifier le code comme ceci et nous donner le résultat?
et nous dire ce qui s'affiche dans ta console?Code:
1
2
3
4
5
6
7
8
9
10
11
12
13try { Socket s1 = new Socket(); s1.bind(null); java.util.Date start = new java.util.Date(); s1.connect(new InetSocketAddress(hostname,port), 500); System.out.println("Délai de tentative: "+(new java.util.Date().getTime()-start.getTime()); b=1; s1.close(); } catch (IOException ex){ return 0; } catch (SocketTimeoutException ex){ return 0; } return b; }
Où je mets ce code dans la même application web ou dans une application normale car j'ai modifié le code et j'ai le meme temps d'exécution que précédent!!
dans ton PScanner
Je l'ai essayé mais sans changement tu as mis System.out alors qu'on est sur Web!
regarde ce que ca affiche dans la console de ton conteneur webapp (vu que je suis dans une méthode, j'ai pas beaucoup d'autre choix que system.out)
Le résultat est le même!!
Le problème est que lorsque la machine est déconnectée le programme se tente de rechercher les services alors qu'il doit passer à la machine suivante!!
elle affiche quoi la console dans ton conteneur?
Elle affiche un tableau qui contient les informations sur chaque machine avec les états des services(flèche UP ou flèche Down).
la console, là ou doit appareitre les system.out du code que je t'ai demandé de changer.
Voilà la console run:
init:
deps-module-jar:
deps-ear-jar:
deps-jar:
library-inclusion-in-archive:
library-inclusion-in-manifest:
compile:
compile-jsps:
do-dist:
dist:
Starting server Bundled Tomcat (5.5.17)
Starting Tomcat process...
Waiting for Tomcat...
Tomcat server started.
Incrementally deploying http://localhost:8084/Essai
Completed incremental distribution of http://localhost:8084/Essai
run-deploy:
Browsing: http://localhost:8084/Essai/
run-display-browser:
run:
BUILD SUCCESSFUL (total time: 22 seconds)
Est ce que je peux afficher le résultat sur console alors que l'application est de type Web?
la console de tomcat, normalement, se trouve dans catalina.out, sauf si t'a démarré tomcat avec des paramètres particuliers (c'est pas parce que c'est une application web qu'elle n'a pas de console pour afficher ses logs, heureusement)
Pour information, ici, ce code:
Affiche ceci: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
34package servers; import java.net.*; import java.io.IOException; public class PScanner { public static int scan(String hostname,int port) { int b=1; try { Socket s1 = new Socket(); s1.bind(null); s1.connect(new InetSocketAddress(hostname,port), 500); b=1; s1.close(); } catch (IOException ex) { ex.printStackTrace(); b=0; } return b; } public static void main(String argv[]){ System.out.println("google port 80... "); System.out.println("resultat: "+scan("www.google.com",80)); System.out.println("google port 6969... "); System.out.println("resultat: "+scan("www.google.com",6969)); System.out.println("www.microsoft.com port 6969... "); System.out.println("resultat: "+scan("www.microsoft.com",6969)); System.out.println("192.168.1.99 6969... "); System.out.println("resultat: "+scan("192.168.1.99",6969)); } }
Preuve que le timeout est une solution qui fonctionne. La seule raison pour laquelle ca ne fonctionnerais pas dans ton cas, serait que tu n'a pas mis à jour le code sur ton serveur java / ou que tu n'a pas compilé le code avec les timeout / ou que tu regarde la mauvaise webapp, bref tout ce qui est au delà du code et résultat d'erreur de manipulation.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 java servers.PScanner google port 80... resultat: 1 google port 6969... java.net.SocketTimeoutException: connect timed out 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:519) at servers.PScanner.scan(PScanner.java:13) at servers.PScanner.main(PScanner.java:28) resultat: 0 www.microsoft.com port 6969... java.net.SocketTimeoutException: connect timed out 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:519) at servers.PScanner.scan(PScanner.java:13) at servers.PScanner.main(PScanner.java:30) resultat: 0 192.168.1.99 6969... java.net.SocketTimeoutException: connect timed out 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:519) at servers.PScanner.scan(PScanner.java:13) at servers.PScanner.main(PScanner.java:32) resultat: 0