Skip to content

Commit

Permalink
using ip instead of hostname for tcp socket connection
Browse files Browse the repository at this point in the history
  • Loading branch information
Lee Felarca committed Jul 27, 2021
1 parent 0243f02 commit b2f647f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
18 changes: 8 additions & 10 deletions proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const dgram = require('dgram');
const net = require("net");
const fastXmlParser = require('fast-xml-parser');

const TROUBLESHOOTING_URL = 'https://github.com/zeropointnine/hqpwv/blob/master/readme_enduser.md';
const UDP_ADDRESS = "239.192.0.199";
const PORT = 4321;
const XML_HEADER = `<?xml version="1.0" encoding="UTF-8"?>`;
Expand All @@ -18,7 +19,6 @@ const XML_PARSER_OPTIONS = { ignoreAttributes : false };

let initCallback;
let timeoutId;
let hqpHostname;
let hqpIp;

/** UDP socket used for 'discovery' command. */
Expand Down Expand Up @@ -67,9 +67,9 @@ const onDiscoveryTimeout = () => {
console.log(`\nERROR: No response from HQPlayer`);
console.log(`\nTIPS:`);
console.log(`1. Verify HQPlayer Desktop is currently running`);
console.log(` (preferably on the same computer as the HQPWV server).`);
console.log(`2. Verify HQPlayer's Settings dialog is not open.`);
console.log(`3. Verify HQPlayer "Allow control from network" button is enabled.`);
console.log(`4. For more troubleshooting info, see ${TROUBLESHOOTING_URL}.`);
exitOnKeypress();
};

Expand Down Expand Up @@ -97,14 +97,10 @@ const onDiscoSocketMessage = (msg, rinfo) => {
}
}
if (!hqpHostname) {
console.log(`\nERROR: Received no value for hostname`);
console.log(`\nWARNING: Received no value for hostname`);
console.log(msg.toString());
console.log(error + '\n');
exitOnKeypress();
}
hqpIp = rinfo.address;
console.log(' hostname:', hqpHostname);

initSocket();
};

Expand All @@ -117,13 +113,15 @@ const sendUdpCommand = (message) => {
exitOnKeypress();
}
});
// fyi, reference implementation also does this, but results in an error FOR ME
// fyi, reference implementation also does this, but results in an error for me
// socket.send(message, 4321, "ff08::c7", onError);
};

const initSocket = () => {
console.log(`- connecting to tcp socket ${hqpHostname}:${PORT}`);
socket = net.createConnection(PORT, hqpHostname, () => {
console.log(`- connecting to tcp socket ${hqpIp}:${PORT}`);
// Note, could also create connection using hostname instead of IP.
// IP has proven to be more reliable when reconnecting windows hqpwv server to mac hqplayer, fwiw.
socket = net.createConnection(PORT, hqpIp, () => {
console.log('- tcp socket connected'); // rem, still need to wait for 'ready'
});
socket.on("error", onSocketError);
Expand Down
6 changes: 3 additions & 3 deletions www/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,14 +294,14 @@ export default class App {
}

showHqpDisconnectedSnack(errorCode) {
const title = `The HQPWV Server has lost connection to HQPlayer`;
const title = `HQPWV Server has lost connection to HQPlayer`;
let msg = `Make sure HQPlayer is running. <span class="colorTextLess"><a href="${Values.TROUBLESHOOTING_HREF}">Troubleshooting tips<a>.</span>`;
SnackView.show('hqp-disconnected', title, msg);
}

showServerErrorsSnack(statusCode) {
const title = `The HQPWV Server is not responding`;
let msg = `Restart HQPWV Server if necessary. <span class="colorTextLess"><a href="${Values.TROUBLESHOOTING_HREF}">Troubleshooting tips<a>.</span>`;
const title = `HQPWV Server is not responding`;
let msg = `Restart server if necessary. <span class="colorTextLess"><a href="${Values.TROUBLESHOOTING_HREF}">Troubleshooting tips<a>.</span>`;
SnackView.show('server-error', title, msg);
}
}

0 comments on commit b2f647f

Please sign in to comment.