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 44import cc .arduino .packages .Discovery ;
55import cc .arduino .packages .discoverers .network .NetworkChecker ;
66import processing .app .Base ;
7+ import processing .app .helpers .NetUtils ;
78import processing .app .helpers .PreferencesMap ;
89import processing .app .zeroconf .jmdns .ArduinoDNSTaskStarter ;
910
1011import javax .jmdns .*;
1112import javax .jmdns .impl .DNSTaskStarter ;
1213import java .io .IOException ;
13- import java .net .Inet4Address ;
1414import java .net .InetAddress ;
1515import java .net .UnknownHostException ;
1616import java .util .*;
@@ -33,14 +33,11 @@ public List<BoardPort> discovery() {
3333 Iterator <BoardPort > iterator = ports .iterator ();
3434 while (iterator .hasNext ()) {
3535 try {
36- InetAddress address = Inet4Address .getByName (iterator .next ().getAddress ());
37- if (!address .isReachable (100 )) {
36+ if (!NetUtils .isReachable (InetAddress .getByName (iterator .next ().getAddress ()))) {
3837 iterator .remove ();
3938 }
4039 } catch (UnknownHostException e ) {
4140 iterator .remove ();
42- } catch (IOException e ) {
43- iterator .remove ();
4441 }
4542 }
4643 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