Changeset 164 for trunk/sonorous
- Timestamp:
- 29/04/10 23:20:16 (4 months ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
trunk/sonorous/uk.co.matbooth.upnp/src/uk/co/matbooth/upnp/discovery/SearchThread.java
r163 r164 2 2 3 3 import java.io.IOException; 4 import java.net.Inet6Address; 4 5 import java.net.InetAddress; 6 import java.net.NetworkInterface; 5 7 import java.net.SocketTimeoutException; 6 8 import java.util.ArrayList; 7 9 import java.util.Date; 10 import java.util.Enumeration; 8 11 import java.util.List; 9 12 … … 13 16 14 17 /** 15 * A thread that sends an SSDP search request from a socket bound to every network16 * interface attached to the local host and listens for responses from UPnP devices17 * announcing their presence on the network.18 * A thread that sends an SSDP search request and listens for responses from UPnP devices 19 * announcing their presence on the network. A request will be sent to every network the 20 * host machine is connected to. 18 21 */ 19 22 public class SearchThread extends DiscoveryThread { … … 38 41 39 42 /** 40 * TODO43 * Creates the search thread. 41 44 */ 42 45 public SearchThread() { 43 // TODO create a socket for each network interface attached to this machine!44 46 try { 45 Socket sock = new Socket(InetAddress.getLocalHost().getHostAddress(), 0); 46 socks.add(sock); 47 // Create a socket for every address of every interface on the machine 48 Enumeration<NetworkInterface> nis = NetworkInterface.getNetworkInterfaces(); 49 while (nis.hasMoreElements()) { 50 NetworkInterface ni = (NetworkInterface) nis.nextElement(); 51 Enumeration<InetAddress> addrs = ni.getInetAddresses(); 52 while (addrs.hasMoreElements()) { 53 InetAddress addr = addrs.nextElement(); 54 // TODO support IPv6 55 if (addr.isLoopbackAddress() || addr instanceof Inet6Address) 56 continue; 57 Socket sock = new Socket(addr.getHostAddress(), 0); 58 socks.add(sock); 59 } 60 } 47 61 } catch (Exception e) { 48 62 // If we can't create a socket for this network interface then just shrug it 49 63 // off and don't bother 64 //TODO warn 65 e.printStackTrace(); 50 66 } 51 67 } … … 69 85 int timeout = (MAX_TIME + ADDITIONAL_TIME) * SEARCH_ATTEMPTS * 1000; 70 86 for (Socket sock : socks) { 71 Thread t = new Thread(new SearchResponseThread(sock, timeout), "UPnP Discovery Search Response"); 87 Thread t = new Thread(new SearchResponseThread(sock, timeout), 88 "UPnP Discovery Search Response"); 72 89 t.setDaemon(true); 73 90 t.start(); … … 121 138 // TODO Auto-generated catch block 122 139 e.printStackTrace(); 140 } finally { 141 sock.close(); 123 142 } 124 143 }