Skip to content

Instantly share code, notes, and snippets.

@alreadysabbir
Last active September 24, 2022 23:42
Show Gist options
  • Save alreadysabbir/37570f1fb63d3249c5e4532f05ff7006 to your computer and use it in GitHub Desktop.
Save alreadysabbir/37570f1fb63d3249c5e4532f05ff7006 to your computer and use it in GitHub Desktop.
const dgram = require('dgram');
const parser = require('http-string-parser');
const client = dgram.createSocket('udp4');
const SSDP_ADDR = "239.255.255.250";
const SSDP_PORT = 1900;
const SSDP_MX = 10;
const SSDP_ST = "urn:schemas-sony-com:service:ScalarWebAPI:1";
const SSDP_MSG = [
`M-SEARCH * HTTP/1.1`,
`HOST: ${SSDP_ADDR}:${SSDP_PORT}`,
`MAN: "ssdp:discover"`,
`MX: ${SSDP_MX}`,
`ST: ${SSDP_ST}`,
`USER-AGENT: sabbir`,
`\r\n`
].join("\r\n");
const message = Buffer.from(SSDP_MSG, 'utf8');
client.send(message, SSDP_PORT, SSDP_ADDR, (err) => {
if (err) console.error(err)
});
client.on('message', (msg, rinfo) => {
const response = parser.parseResponse(msg.toString('utf8'))
console.log(response);
client.close()
});
client.on("listening", () => console.log("Listening"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment