diff --git a/src/zutil/net/dns/MulticastDNSClient.java b/src/zutil/net/dns/MulticastDNSClient.java index 9551bdc..0564c44 100755 --- a/src/zutil/net/dns/MulticastDNSClient.java +++ b/src/zutil/net/dns/MulticastDNSClient.java @@ -55,7 +55,7 @@ public class MulticastDNSClient extends ThreadedUDPNetwork implements ThreadedUD public MulticastDNSClient() throws IOException { - super(null, MDNS_MULTICAST_ADDR, MDNS_MULTICAST_PORT); + super(MDNS_MULTICAST_ADDR, MDNS_MULTICAST_PORT); setThread( this ); } diff --git a/src/zutil/net/ssdp/SSDPClient.java b/src/zutil/net/ssdp/SSDPClient.java index 03626fc..295574b 100755 --- a/src/zutil/net/ssdp/SSDPClient.java +++ b/src/zutil/net/ssdp/SSDPClient.java @@ -26,7 +26,7 @@ package zutil.net.ssdp; import zutil.io.StringOutputStream; import zutil.log.LogUtil; -import zutil.net.http.HttpHeader; +import zutil.net.http.HttpHeader; import zutil.net.http.HttpHeaderParser; import zutil.net.http.HttpPrintStream; import zutil.net.threaded.ThreadedUDPNetwork; @@ -63,7 +63,6 @@ public class SSDPClient extends ThreadedUDPNetwork implements ThreadedUDPNetwork * @throws IOException */ public SSDPClient() throws IOException{ - super(null); super.setThread(this); services_st = new HashMap<>(); @@ -190,45 +189,45 @@ public class SSDPClient extends ThreadedUDPNetwork implements ThreadedUDPNetwork * Location: http://localhost:80 */ public void receivedPacket(DatagramPacket packet, ThreadedUDPNetwork network) { - try { - String msg = new String(packet.getData(), packet.getOffset(), packet.getLength()); - HttpHeaderParser headerParser = new HttpHeaderParser(msg); - HttpHeader header = headerParser.read(); - logger.log(Level.FINEST, "Received(from: " + packet.getAddress() + "): " + header); + try { + String msg = new String(packet.getData(), packet.getOffset(), packet.getLength()); + HttpHeaderParser headerParser = new HttpHeaderParser(msg); + HttpHeader header = headerParser.read(); + logger.log(Level.FINEST, "Received(from: " + packet.getAddress() + "): " + header); - String usn = header.getHeader("USN"); - String st = header.getHeader("ST"); - boolean newService = false; - StandardSSDPInfo service; - // Get existing service - if (services_usn.containsKey(usn)) { - service = services_usn.get(usn); - } - // Add new service - else { - newService = true; - service = new StandardSSDPInfo(); - services_usn.put(usn, service); - if (!services_st.containsKey(st)) - services_st.put(st, new LinkedList()); - services_st.get(header.getHeader("ST")).add(service); - } - - service.setLocation(header.getHeader("LOCATION")); - service.setST(st); - service.setUSN(usn); - service.setInetAddress(packet.getAddress()); - if (header.getHeader("Cache-Control") != null) { - service.setExpirationTime( - System.currentTimeMillis() + 1000 * getCacheTime(header.getHeader("Cache-Control"))); - } - service.readHeaders(header); - - if (listener != null && newService) - listener.newService(service); - } catch (IOException e){ - logger.log(Level.SEVERE, null, e); - } + String usn = header.getHeader("USN"); + String st = header.getHeader("ST"); + boolean newService = false; + StandardSSDPInfo service; + // Get existing service + if (services_usn.containsKey(usn)) { + service = services_usn.get(usn); + } + // Add new service + else { + newService = true; + service = new StandardSSDPInfo(); + services_usn.put(usn, service); + if (!services_st.containsKey(st)) + services_st.put(st, new LinkedList()); + services_st.get(header.getHeader("ST")).add(service); + } + + service.setLocation(header.getHeader("LOCATION")); + service.setST(st); + service.setUSN(usn); + service.setInetAddress(packet.getAddress()); + if (header.getHeader("Cache-Control") != null) { + service.setExpirationTime( + System.currentTimeMillis() + 1000 * getCacheTime(header.getHeader("Cache-Control"))); + } + service.readHeaders(header); + + if (listener != null && newService) + listener.newService(service); + } catch (IOException e){ + logger.log(Level.SEVERE, null, e); + } } private long getCacheTime(String cache_control){ diff --git a/src/zutil/net/ssdp/SSDPServer.java b/src/zutil/net/ssdp/SSDPServer.java index 457a97f..a5471d2 100755 --- a/src/zutil/net/ssdp/SSDPServer.java +++ b/src/zutil/net/ssdp/SSDPServer.java @@ -83,7 +83,7 @@ public class SSDPServer extends ThreadedUDPNetwork implements ThreadedUDPNetwork public SSDPServer() throws IOException{ - super( null, SSDP_MULTICAST_ADDR, SSDP_PORT ); + super( SSDP_MULTICAST_ADDR, SSDP_PORT ); super.setThread( this ); services = new HashMap(); diff --git a/src/zutil/net/threaded/ThreadedUDPNetwork.java b/src/zutil/net/threaded/ThreadedUDPNetwork.java old mode 100644 new mode 100755 index 4087e7c..2850056 --- a/src/zutil/net/threaded/ThreadedUDPNetwork.java +++ b/src/zutil/net/threaded/ThreadedUDPNetwork.java @@ -49,49 +49,43 @@ public class ThreadedUDPNetwork extends Thread{ /** * Creates a new unicast Client instance of the class - * - * @param thread is the class that will handle incoming packets + * * @throws SocketException */ - public ThreadedUDPNetwork(ThreadedUDPNetworkThread thread) throws SocketException{ + public ThreadedUDPNetwork() throws SocketException{ this.type = UDPType.UNICAST; this.port = -1; - setThread( thread ); socket = new DatagramSocket(); } /** * Creates a new unicast Server instance of the class - * - * @param thread is the class that will handle incoming packets - * @param port is the port that the server should listen to + * + * @param port is the port that the server should listen to * @throws SocketException */ - public ThreadedUDPNetwork(ThreadedUDPNetworkThread thread, int port) throws SocketException{ + public ThreadedUDPNetwork(int port) throws SocketException{ this.type = UDPType.UNICAST; this.port = port; - setThread( thread ); socket = new DatagramSocket( port ); } /** * Creates a new multicast Server instance of the class - * - * @param thread is the class that will handle incoming packets - * @param port is the port that the server should listen to - * @param multicast_addr is the multicast address that the server will listen on + * + * @param port is the port that the server should listen to + * @param multicastAddr is the multicast address that the server will listen on * @throws IOException */ - public ThreadedUDPNetwork(ThreadedUDPNetworkThread thread, String multicast_addr, int port ) throws IOException{ + public ThreadedUDPNetwork(String multicastAddr, int port ) throws IOException{ this.type = UDPType.MULTICAST; this.port = port; - setThread( thread ); // init udp socket MulticastSocket msocket = new MulticastSocket( port ); - InetAddress group = InetAddress.getByName( multicast_addr ); + InetAddress group = InetAddress.getByName( multicastAddr ); msocket.joinGroup( group ); socket = msocket; @@ -115,7 +109,7 @@ public class ThreadedUDPNetwork extends Thread{ /** * Sends the given packet * - * @param packet is the packet to send + * @param packet is the packet to send * @throws IOException */ public synchronized void send( DatagramPacket packet ) throws IOException{ @@ -125,7 +119,7 @@ public class ThreadedUDPNetwork extends Thread{ /** * Sets the thread that will handle the incoming packets * - * @param thread is the thread + * @param thread is the thread */ public void setThread(ThreadedUDPNetworkThread thread){ this.thread = thread;