Your Universal Remote Control Center
Philips Pronto Professional Forum - View Post
Up level
Up level
The following page was printed from


Original thread:
Post 2 made on Saturday August 22, 2020 at 20:04
Lyndel McGee
RC Moderator
August 2001
The queue is definitely the best approach.

Use an array for the queue. Do .push(entry) to add things to the end and .shift() to remove the first entry.

This is one way to do it. The queue just guarantees an ordered write.

var queue = [];
var buffer = '';
var activeCommand = null;

function sendSomething(toSend) {

function sendNext() {
if (activeCommand) {

if (socket && socket.connected && queue.length) {
activeCommand = queue.shift();

function onConnect() {
// if any commands have been queued

function cleanupSocket() {
if (socket) {
if (socket.connected) {
socket.onData = null;
socket.onIOError = null;
socket.onConnect = null;
socket = null;

function onIOError() {

function onData() {
// within onData, 'this' and socket are one in the same.
buffer +=;
// process any data that was read.
// blah blah blah
// assume that if you received a message, server is ready for next command.
activeCommand = null;
// send next command.

Note that ideally, you might want to use a scheduleAfter() to clear activeCommand and then call sendNext Periodically in case the server does not respond.

Finally, the code above does not manage reconnects should the server close the socket. I leave that exercise up to you. I would recommend that in onIOError that you use scheduleAfter to do a reconnect.


I edited the above after a re-read and also added onConnect and onIOError as an example.

I do what you ask specifically in my Denon TCP/IP module but as I use 2 queues (priority and background), the code is more complicated than needed for this purpose.

If you will be so kind as to email me at my address on profile, I can help you work out the details of how to use a single socket that reconnects as needed and also uses a queue to manage commands. Email me your PS Library or your config I will have a look. If you are in the USA, I don't mind having a phone call (or facetime) to talk through the details.

Last edited by Lyndel McGee on August 23, 2020 09:49.
Lyndel McGee
Philips Pronto Addict/Beta Tester

Hosting Services by ipHouse