Last active
August 29, 2015 13:57
-
-
Save brendonanderson/9641872 to your computer and use it in GitHub Desktop.
UPnP Blog - send discovery packet
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
InetSocketAddress socketAddress | |
= new InetSocketAddress(InetAddress.getByName("239.255.255.250"), 1900) | |
MulticastSocket socket = new MulticastSocket(null) | |
try { | |
socket.bind(new InetSocketAddress("192.168.1.150", 1901)) | |
StringBuilder packet = new StringBuilder() | |
packet.append( "M-SEARCH * HTTP/1.1\r\n" ) | |
packet.append( "HOST: 239.255.255.250:1900\r\n" ) | |
packet.append( "MAN: \"ssdp:discover\"\r\n" ) | |
packet.append( "MX: ").append( "5" ).append( "\r\n" ) | |
packet.append( "ST: " ).append( "ssdp:all" ).append( "\r\n" ).append( "\r\n" ) | |
//packet.append( "ST: " ).append( "urn:Belkin:device:controllee:1" ).append( "\r\n" ).append( "\r\n" ) | |
byte[] data = packet.toString().bytes | |
socket.send(new DatagramPacket(data, data.length, socketAddress)) | |
} catch (IOException e) { | |
throw e | |
} finally { | |
socket.disconnect() | |
socket.close() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment