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

Login:
Pass:
 
 

Original thread:
Post 37 made on Thursday August 6, 2020 at 17:46
Lyndel McGee
RC Moderator
Joined:
Posts:
August 2001
12,996
Your scheduleAfter(100,Kodi3) needs to be called from within either onData or onClose function as it likely depends on data you are receiving from within Kodi or Kodi2 function?

I think there may be a misunderstanding on when certain functions execute in what you are developing.

Only the lines creating the socket and the actual connect function execute at the time kodi() is invoked.

The other functions such as onConnect, onData, onClose and onIOError execute after something has happened on a socket.

onConnect will be executed when the underlying socket connects to the server.
onData will be executed each time a block of data is available from the server.
onClose will be executed when the remote server closes the socket.
onIOError will be executed if there an an underlying socket error.

Once you understand that all these things don't execute at once but rather based on event triggers, you are one up in the game.

Next, if you are interested in why the above applies and why the examples do it this way...

The pattern you are using is called javascript closures. You are creating new functions at the time your kodi() function is executing. What this does is to allow those functions to be able to use and have visibility to a common 'receivedData' and 'socket' variable if need be.

I know you are trying to learn this on your own. The solution you require is complex and requires asynchronous programming expertise as well.

There are about 6 different items that are required for this solution.

1. Core Javascript + Closures/Variable Scoping
2. Asynchronous coding using Javascript Callbacks.
3. ProntoScript object extensions to JavaScript
4. Deep understanding of the HTTP protocol (using raw TCPSockets)
5. JavaScript Object Notation (JSON)
6. JSON Remote Procedure Calls (JSONRPC v2.0)
7. Creating an image from HTTP response data.


I offered to reach out to you via telephone for some pointers if need be. I don't think I got a response. The offer still stands as there is often alot that is lost in translation through a forum.

Last edited by Lyndel McGee on August 6, 2020 17:57.
Lyndel McGee
Philips Pronto Addict/Beta Tester


Hosting Services by ipHouse