Skip to content

Instantly share code, notes, and snippets.

@brendonanderson
Created March 19, 2014 14:23
Show Gist options
  • Save brendonanderson/9642651 to your computer and use it in GitHub Desktop.
Save brendonanderson/9642651 to your computer and use it in GitHub Desktop.
UPnP Blog - listener
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