File tree Expand file tree Collapse file tree 2 files changed +30
-5
lines changed
cc/arduino/packages/discoverers Expand file tree Collapse file tree 2 files changed +30
-5
lines changed Original file line number Diff line number Diff line change 4
4
import cc .arduino .packages .Discovery ;
5
5
import cc .arduino .packages .discoverers .network .NetworkChecker ;
6
6
import processing .app .Base ;
7
+ import processing .app .helpers .NetUtils ;
7
8
import processing .app .helpers .PreferencesMap ;
8
9
import processing .app .zeroconf .jmdns .ArduinoDNSTaskStarter ;
9
10
10
11
import javax .jmdns .*;
11
12
import javax .jmdns .impl .DNSTaskStarter ;
12
13
import java .io .IOException ;
13
- import java .net .Inet4Address ;
14
14
import java .net .InetAddress ;
15
15
import java .net .UnknownHostException ;
16
16
import java .util .*;
@@ -33,14 +33,11 @@ public List<BoardPort> discovery() {
33
33
Iterator <BoardPort > iterator = ports .iterator ();
34
34
while (iterator .hasNext ()) {
35
35
try {
36
- InetAddress address = Inet4Address .getByName (iterator .next ().getAddress ());
37
- if (!address .isReachable (100 )) {
36
+ if (!NetUtils .isReachable (InetAddress .getByName (iterator .next ().getAddress ()))) {
38
37
iterator .remove ();
39
38
}
40
39
} catch (UnknownHostException e ) {
41
40
iterator .remove ();
42
- } catch (IOException e ) {
43
- iterator .remove ();
44
41
}
45
42
}
46
43
return ports ;
Original file line number Diff line number Diff line change
1
+ package processing .app .helpers ;
2
+
3
+ import java .io .IOException ;
4
+ import java .net .InetAddress ;
5
+ import java .net .InetSocketAddress ;
6
+ import java .net .Socket ;
7
+
8
+ public abstract class NetUtils {
9
+
10
+ public static boolean isReachable (InetAddress address ) {
11
+ Socket socket = null ;
12
+ try {
13
+ socket = new Socket ();
14
+ socket .connect (new InetSocketAddress (address , 80 ), 100 );
15
+ return true ;
16
+ } catch (IOException e ) {
17
+ return false ;
18
+ } finally {
19
+ if (socket != null ) {
20
+ try {
21
+ socket .close ();
22
+ } catch (IOException e ) {
23
+ // noop
24
+ }
25
+ }
26
+ }
27
+ }
28
+ }
You can’t perform that action at this time.
0 commit comments