UDPSocket

This article needs a technical review. How you can help.

Non-standard
This feature is non-standard and is not on a standards track. Do not use it on production sites facing the Web: it will not work for every user. There may also be large incompatibilities between implementations and the behavior may change in the future.

This API is available on Firefox OS for privileged or certified applications only.

Example API call

var SSDP_PORT = 1900;
var SSDP_ADDRESS = "239.255.255.250";
var SSDP_DISCOVER_MX = 2;
var SEARCH_TARGET = "urn:schemas-upnp-org:service:ContentDirectory:1";

var SSDP_DISCOVER_PACKET =
    "M-SEARCH * HTTP/1.1\r\n" +
    "HOST: " + SSDP_ADDRESS + ":" + SSDP_PORT + "\r\n" +
    "MAN: \"ssdp:discover\"\r\n" +
    "MX: " + SSDP_DISCOVER_MX + "\r\n" +
    "ST: " + SEARCH_TARGET + "\r\n" +
    "\r\n";

var searchSocket = new UDPSocket({
    loopback: true
});

searchSocket.joinMulticastGroup(SSDP_ADDRESS);

searchSocket.onmessage = function (e) {

    var msg = String.fromCharCode.apply(null, new Uint8Array(e.data));
    
    console.log(msg);
};

searchSocket.opened.then(function() {
    
    searchSocket.send(SSDP_DISCOVER_PACKET, SSDP_ADDRESS, SSDP_PORT);
    
    setTimeout(function () { searchSocket.close(); }, SSDP_DISCOVER_MX * 1000);
});

Example manifest

{
  "name": "My App",
  "launch_path": "/index.html",
  "icons": {
  },
  "developer": {
  },
  "type": "privileged",
  "permissions": {
    "udp-socket": { "description": "Required to do any UDP" }
  },
  "default_locale": "en"
}

Document Tags and Contributors

 Contributors to this page: chrisdavidmills, teoli, rolfedh, SunboX
 Last updated by: chrisdavidmills,