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


Original thread:
Post 1 made on Saturday August 22, 2020 at 18:26
Long Time Member
June 2003
I know this is likely a lack of core JS knowledge on my part, but can't work it out ...

I have a function which opens an async socket to my satellite box and uses onconnect and ondata to send command to the box. All works fine. The problem is that if I send multiple commands one after another, the callbacks from earlier commands haven't completed, so I end up with multiple sockets open and the server reaches a limit and stops accepting new connections. So, how to get over this. The obvious thing seems to be to try and turn the async socket into something that is more like a sync socket - don't return from the calling function until the callbacks are finished. But, that goes against the whole idea of callbacks and the async nature of javascript. Is this possible, or do I need to take a different approach. I can see something using a queue instead (put the commands onto a queue, at the end of the callback see if there's anything in the queue and if there is, call the connect command again) but that sounds messy (e.g. the first call would need to be different to call the function first time around).

What's the right way to approach this. At heart, I want to be able to send a number of commands to a server, but only open a single socket.


pete S

Hosting Services by ipHouse