Created
March 19, 2014 14:23
-
-
Save brendonanderson/9642651 to your computer and use it in GitHub Desktop.
UPnP Blog - listener
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MulticastSocket recSocket = new MulticastSocket(null) | |
recSocket.bind(new InetSocketAddress(InetAddress.getByName("0.0.0.0"), 1901)) | |
recSocket.setTimeToLive(10) | |
recSocket.setSoTimeout(1000) | |
recSocket.joinGroup(InetAddress.getByName("239.255.255.250")) | |
while (inService) { //inService is a variable controlled by a thread to stop the listener | |
byte[] buf = new byte[2048] | |
DatagramPacket input = new DatagramPacket(buf, buf.length) | |
try { | |
recSocket.receive(input) | |
String originaldata = new String(input.data) | |
} catch (SocketTimeoutException e) { | |
} | |
} | |
recSocket.disconnect() | |
recSocket.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment