Your Universal Remote Control Center
RemoteCentral.com
Philips Pronto Professional Forum - View Post
Previous section Next section Up level
Up level
The following page was printed from RemoteCentral.com:

Login:
Pass:
 
 

Topic:
How to abort all asynchronous instances in a pronto script
This thread has 3 replies. Displaying all posts.
Post 1 made on November 10, 2024 at 06:07
F
Fbrighi
Long Time Member
Joined:
Posts:
September 2010
54
Hello!

I have discovered a "malfunction" within one of my script using pronto pro, i try to explain it in few words.

There is one page which is repeated each 0.5 sec to recover data from a mediaplayer, and make eventual actions depending on data result. The main point is this variables attribution (PlayBackStatus & ElapsedSec):

PlayBackStatus = LanAskAs(hostIPzidoo,hostPORTzidoo,"GET /ZidooVideoPlay/getPlayStatus HTTP/1.0\r\n\r\n");

ElapsedSec = parseInt(PlayBackStatus.split(",")[4].substring(18)/1000); //Tempo trascorso file corrente in secondi

Now what happens. After ending those reading of data after the file playing finishe, script stays in stand-by waiting for new play. When new file play starts, the ElapsedSec remains the latest old values read. This causes malfunction of script since it expects new file, so new ElapsedSec value.

I tried put ElapsedSec = 0 in several positions, but not way: it reports last value from previosus file.

Now my suspect: could it be that the LanAskAs instance (see below), beeing a a-synchronous instance for LAN reading data, remains active even when new file is started?

function LanAskAs(targetIP,targetPort,commandString)
{
var socket, result;
socket = new TCPSocket(false);
result = "";
socket.onConnect = function()
{
socket.write(commandString);
};
socket.onData = function()
{
result += socket.read();
};
socket.onClose = function()
{
Output = result;
};
socket.connect(targetIP,targetPort,3000);
return Output;
}

Consequent question: is it possible to reset all async communication when one file is ended?

Thanks!

FKB
Post 2 made on November 10, 2024 at 13:35
L
MOD
Lyndel McGee
RC Moderator
Joined:
Posts:
RC XP:
August 2001
13,125
389⭐︎
You can send an HTTP Connection: close header and hope that the server will close the socket.

Add this when building your HTTP request and see if it helps.

"Connection: close\r\n"

Here's an example I found searching for close\r\n.

socket_bri.write('PUT /api/newdeveloper/groups/all/action HTTP/1.1\r\nConnection: close\r\nContent-Length: '+commands.length+'\r\n\r\n'+commands);

Otherwise, it is 100% up to you to close out your socket when you receive the data that you want. The issue you have here is that the variable 'socket' is scoped to the function LanAskAs. Maybe you should keep a list of all sockets that are open so you can close them out as needed. Note that the Pronto has a limit of 32 open sockets that can be increased. See the Dev Guide for more info. I believe it was System.setSocketLimit or something like that.

If you are using scheduleAfter() in your setup, then you need a way to tell the existing task that it should not be rescheduled (a flag for example).

As I cannot see all of your code, I can only offer these suggestions.

Regards,
Lyndel

Lyndel McGee
Philips Pronto Addict/Beta Tester
OP | Post 3 made on November 11, 2024 at 07:20
F
Fbrighi
Long Time Member
Joined:
Posts:
September 2010
54
Hello! Thanks for the reply. I tried with no success with the connection : close ... but after that, your mentioning of schedule.After() gave me inspiration.

There is one instance that, when file is near end, turns a boolean variable to false to stop all LAN instances. This not to overload the system when file is not under playing.

I changed the boolean turning to false by using scheduling.After, so to leave 5 seconds of LAN activity before stopping it. That worked, doing so the LanAskAs terminates and ElapsedSec is correctly updated to 0 value. Now it works !

Thanks!!!!

FKB

FKB
Post 4 made on November 11, 2024 at 16:43
L
MOD
Lyndel McGee
RC Moderator
Joined:
Posts:
RC XP:
August 2001
13,125
389⭐︎
Asynchronous socket code is always tedious and requires care to implement properly. Glad you found a solution.

Just a thought. If you are using the HTTP protocol and the response is not "chunked", you could use the Content-Length response header to tell you when you have read all the data and upon reading all the data, close the socket.

Last edited by Lyndel McGee on November 11, 2024 18:05.
Lyndel McGee
Philips Pronto Addict/Beta Tester

Jump to


Protected Feature Before you can reply to a message...
You must first register for a Remote Central user account - it's fast and free! Or, if you already have an account, please login now.

Please read the following: Unsolicited commercial advertisements are absolutely not permitted on this forum. Other private buy & sell messages should be posted to our Marketplace. For information on how to advertise your service or product click here. Remote Central reserves the right to remove or modify any post that is deemed inappropriate.