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:
TSU9600 : socket connection not working when used in a "for" iteration
This thread has 3 replies. Displaying all posts.
Post 1 made on Wednesday July 19, 2017 at 04:01
Fbrighi
Long Time Member
Joined:
Posts:
September 2010
42
Hello all,

I have a question regarding javascript programming of tsu9600 if someone could give me a suggestion.

I have programmed a routine that, given a file name (FileSQ), shows the first text line within it in the "ribbon" widget. Here it is :

var EDev = {};
var hostIP = "readyshare.routerlogin.net"; //Dominio contenuto server
var hostPORT = 80;
var hostDir = 'shares/U/KMS-Storage'; //Percorso file contenuto server
var loadData = '';
var hostFile= encodeURIComponent(FileSQ); //File contenuto server
var List = "";

EDev.socket = new TCPSocket(false);
EDev.socket.onConnect = function() {
EDev.socket.write( "GET /"+ hostDir + hostFile + " HTTP/1.0\r\n\r\n");
};
EDev.socket.onIOError = function (e) {System.print("IOError " + e)};
EDev.socket.onData = function() {loadData += EDev.socket.read();
};
EDev.socket.onClose = function() {EDev.socket=null;

In = loadData.indexOf("#");
Fi = loadData.lastIndexOf("#");
List = loadData.substring(In, Fi);

contenutofile = List;

check = false;
Inizio = 1;
Fine = Inizio+1;
while (check == false) {
if (contenutofile.substring(Fine,Fine+1) == "#") {
Titolo = contenutofile.substring(Inizio,Fine);
check = true;
} else {
Fine = Fine + 1;
}
}

ribbon.label = Titolo;

};
EDev.socket.connect(hostIP,hostPORT, 3000);

Since I need to show on the widget a series of files lines, I tried to use this routine in a for cycle, cycling also file name transferred (files are named Playlist 1, Playlist 2 ecc, so it is enough to create strings accordingly and pass them to the routine).
But if I do so, system is not working reporting "socket error". I tried several ways but never succeded. Also testing a synchronous routine, if used in a cycle, the system reports "socket error".

Someone that is more skilled than me on this, could give some suggestion about reason and, if existing, a possible solution?

Thanks and regards
FKB
FKB
Post 2 made on Thursday July 20, 2017 at 23:26
cosmicvoid
Long Time Member
Joined:
Posts:
November 2007
88
I only have a little experience using Prontoscript, but I can make 2 suggestions.

1. maybe the declaration
var loadData = '';
should have two quotes (i.e. var loadData = "";), like the var List. I am not sure how fussy Prontoscript is about things like that.

2. I would greatly improve the readability of your code to put opening braces ( '{' ) on a separate line, much like your closing braces ( '}' ).
Post 3 made on Saturday July 22, 2017 at 22:18
Lyndel McGee
RC Moderator
Joined:
Posts:
August 2001
12,156
After you read all the data, are you closing the socket? I suspect the host is closing the socket at the end as you are using http 1.0. However, this is not guaranteed with some servers...

Add a System.print() message inside the onClose function to check.

I suspect you are running out of sockets. I think there is a limit of 16 or 64 sockets that can be open at one time.
Lyndel McGee
Philips Pronto Addict/Beta Tester
Post 4 made on Sunday July 23, 2017 at 14:44
Lyndel McGee
RC Moderator
Joined:
Posts:
August 2001
12,156
And, if you are planning to use the above logic for multiple files at one time, you should make the variable 'loadData' a field inside of EDV. Otherwise, multiple sockets being active will corrupt the value if onData is called for different sockets at the same time.
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.

Hosting Services by ipHouse