diff --git a/arduino-core/src/cc/arduino/packages/discoverers/NetworkDiscovery.java b/arduino-core/src/cc/arduino/packages/discoverers/NetworkDiscovery.java index 85cd05c66..106b50924 100644 --- a/arduino-core/src/cc/arduino/packages/discoverers/NetworkDiscovery.java +++ b/arduino-core/src/cc/arduino/packages/discoverers/NetworkDiscovery.java @@ -58,19 +58,35 @@ public class NetworkDiscovery implements Discovery, ServiceListener, cc.arduino. @Override public List discovery() { - List ports = clonePortsList(); - Iterator iterator = ports.iterator(); - while (iterator.hasNext()) { + List boardPorts = clonePortsList(); + Iterator boardPortIterator = boardPorts.iterator(); + while (boardPortIterator.hasNext()) { try { - BoardPort board = iterator.next(); - if (!NetUtils.isReachable(InetAddress.getByName(board.getAddress()), Integer.parseInt(board.getPrefs().get("port")))) { - iterator.remove(); + BoardPort board = boardPortIterator.next(); + + InetAddress inetAddress = InetAddress.getByName(board.getAddress()); + int broadcastedPort = Integer.valueOf(board.getPrefs().get("port")); + + List ports = new LinkedList(); + ports.add(broadcastedPort); + + //dirty code: allows non up to date yuns to be discovered. Newer yuns will broadcast port 22 + if (broadcastedPort == 80) { + ports.add(0, 22); + } + + boolean reachable = false; + for (Integer port : ports) { + reachable = reachable || NetUtils.isReachable(inetAddress, port); + } + if (!reachable) { + boardPortIterator.remove(); } } catch (UnknownHostException e) { - iterator.remove(); + boardPortIterator.remove(); } } - return ports; + return boardPorts; } private List clonePortsList() { diff --git a/arduino-core/src/processing/app/helpers/NetUtils.java b/arduino-core/src/processing/app/helpers/NetUtils.java index c67245801..96fe6ff09 100644 --- a/arduino-core/src/processing/app/helpers/NetUtils.java +++ b/arduino-core/src/processing/app/helpers/NetUtils.java @@ -11,7 +11,7 @@ public abstract class NetUtils { Socket socket = null; try { socket = new Socket(); - socket.connect(new InetSocketAddress(address, port), 100); + socket.connect(new InetSocketAddress(address, port), 300); return true; } catch (IOException e) { return false;