mirror of
https://github.com/arduino/Arduino.git
synced 2025-01-18 07:52:14 +01:00
An attempt to improve Yun's discovery. Thanks @roadfun. See #2576
This commit is contained in:
parent
bedc550b5e
commit
3fec636b29
@ -58,19 +58,35 @@ public class NetworkDiscovery implements Discovery, ServiceListener, cc.arduino.
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<BoardPort> discovery() {
|
public List<BoardPort> discovery() {
|
||||||
List<BoardPort> ports = clonePortsList();
|
List<BoardPort> boardPorts = clonePortsList();
|
||||||
Iterator<BoardPort> iterator = ports.iterator();
|
Iterator<BoardPort> boardPortIterator = boardPorts.iterator();
|
||||||
while (iterator.hasNext()) {
|
while (boardPortIterator.hasNext()) {
|
||||||
try {
|
try {
|
||||||
BoardPort board = iterator.next();
|
BoardPort board = boardPortIterator.next();
|
||||||
if (!NetUtils.isReachable(InetAddress.getByName(board.getAddress()), Integer.parseInt(board.getPrefs().get("port")))) {
|
|
||||||
iterator.remove();
|
InetAddress inetAddress = InetAddress.getByName(board.getAddress());
|
||||||
|
int broadcastedPort = Integer.valueOf(board.getPrefs().get("port"));
|
||||||
|
|
||||||
|
List<Integer> ports = new LinkedList<Integer>();
|
||||||
|
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) {
|
} catch (UnknownHostException e) {
|
||||||
iterator.remove();
|
boardPortIterator.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ports;
|
return boardPorts;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<BoardPort> clonePortsList() {
|
private List<BoardPort> clonePortsList() {
|
||||||
|
@ -11,7 +11,7 @@ public abstract class NetUtils {
|
|||||||
Socket socket = null;
|
Socket socket = null;
|
||||||
try {
|
try {
|
||||||
socket = new Socket();
|
socket = new Socket();
|
||||||
socket.connect(new InetSocketAddress(address, port), 100);
|
socket.connect(new InetSocketAddress(address, port), 300);
|
||||||
return true;
|
return true;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
return false;
|
return false;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user