|
|
|
The following page was printed from RemoteCentral.com:
Cannot get Pronto to talk to server...
| |
|
Topic: | Cannot get Pronto to talk to server using Async sockets This thread has 11 replies. Displaying all posts. |
|
Post 1 made on Sunday March 22, 2009 at 18:19 |
macdonm2 Long Time Member |
Joined: Posts: | January 2008 12 |
|
|
Hi,
I wonder if anyone can help. I am writing an application to a Linn Kivor, and I want to download all of the album and track information to the Pronto to allow me to scroll through all of my albums.
At the moment, the only way that I can talk to the server is using a Sync socket on the Pronto but this obviously locks the device while this is operation. When I use a for next loop to run through approx 700 albums, the most that I can download is about 500 before the for-next loop times out.
What I would really like to do is to use an Async socket to talk to the Kivor, but I cannot seem to get any response when I try Async. I suspect that the Kivor is not closing the socket after responding, but even trying to force the socket closed does not have the desired effect.
The code I am using for Sync socket is shown below. The Kivor will always send a '~' at the end of a message so I have tried looking for this on the incoming string and then closing the socket based on this, but this does not seem to work.
I am new to Javascript, so any advice would be gratefully received.
Many thanks.
------------------------
...... if (message_counter==62) message_counter=0; else; message_counter++; var socket = new TCPSocket(true); socket.connect('192.168.1.100', 6789, 3000); var message_out = "#pronto#@"+zone+"@"+message_number[message_counter]+msg+"~"; get_checksum(message_out); socket.write(message_out+checksum+"\r\n"); var output = socket.read(500,200); socket.close(); full_output[0]=output; System.delay(150); ...... ------------------------
|
macdonm2 |
|
Post 2 made on Sunday March 22, 2009 at 20:17 |
bodshal Long Time Member |
Joined: Posts: | January 2009 16 |
|
|
Perhaps paste in the code you try to use for the async Socket?
FWIW, you don't *have* to do everything once the connection closes. This is merely a useful convention for the likes of HTTP which is (most often) a one-transaction-per-connection protocol.
You can (and sometimes have to) do your processing in the data-arrived callback - though you cannot guarantee that all the data you need to work on will arrive in a single invocation of the callback, of course.
Chris.
|
|
Post 3 made on Sunday March 22, 2009 at 22:00 |
Barry Gordon Founding Member |
Joined: Posts: | August 2001 2,157 |
|
|
There are some examples of working with async tcpip sockets posted on my web site www.the-gordons.net. You should be able to find them. If you can't well TCPIP sockets is much harder than browsing around a web site
|
|
OP | Post 4 made on Monday March 23, 2009 at 04:52 |
macdonm2 Long Time Member |
Joined: Posts: | January 2008 12 |
|
|
Hi all,
Thanks for the replys. Barry I will have a look at your website.
Meantime here is the Async code that I am using which returns 'empty socket' telling me that the Ondata subroutine is not being called.
Thanks again for all the help.
var socket = new TCPSocket(); var result = "empty"; socket.onConnect = function() { write("#pronto#@Z01@1$PLAY$~\r\n"); }
socket.onData = function() { //var data = read() result += read(); if (result.indexOf("~") != -1) this.close(); };
socket.onIOError = function(e) { CF.widget("LINE1")= ( "Socket error: " + e); };
socket.connect('192.168.1.100', 6789, 3000); CF.widget("LINE1").label = "finished"+ result;
|
macdonm2 |
|
Post 5 made on Monday March 23, 2009 at 11:05 |
Barry Gordon Founding Member |
Joined: Posts: | August 2001 2,157 |
|
|
Is it your thought that the unqualified read in the onData function, or the unqualified write in the onConnect function will address the socket? It might, as some languages support an implied qualifier and some don't. After all, read could be another fiunction having nothing to do with sockets, or you may have multiple sockets active that need to be read. I always use explicit qualification as a matter of practice
I do know for sure that socket.write will work as will socket.read. Hope that helps
|
|
OP | Post 6 made on Monday March 23, 2009 at 15:40 |
macdonm2 Long Time Member |
Joined: Posts: | January 2008 12 |
|
|
Hello Barry,
Looks like your suggestion was a good one despite the Pronto manual saying that 'read' would work as it was in scope. I can now send commands to the Kivor server which are acted upon but I cannot read the response. The code I am using is as below - I don't get any errors but when I run the script 'LINE1' is showing
receiving + functionread(){ [native code] }
Any ideas
var socket = new TCPSocket(false); var result = ""; socket.onConnect = function() { socket.write("#pronto#@Z01@1$PLAY$~\r\n"); };
socket.onData = function() { var received=socket.read; result += received; CF.widget("LINE1").label="receiving"+ received; };
socket.connect('192.168.1.100', 6789, 3000);
|
macdonm2 |
|
OP | Post 7 made on Monday March 23, 2009 at 15:47 |
macdonm2 Long Time Member |
Joined: Posts: | January 2008 12 |
|
|
OK so I figured it out - missing ()
Here is the working code for anyone else who wishes to use it.
Many thanks to all.
---------------------------------
var socket = new TCPSocket(false); var result = ""; socket.onConnect = function() { socket.write("#pronto#@Z01@1$PLAY$~\r\n"); };
socket.onData = function() { var received=socket.read(); result += received; CF.widget("LINE1").label="receiving"+ received; };
socket.connect('192.168.1.100', 6789, 3000);
|
macdonm2 |
|
Post 8 made on Monday March 23, 2009 at 17:36 |
Lyndel McGee RC Moderator |
Joined: Posts: | August 2001 12,999 |
|
|
FYI, while inside any of the TCPSocket onXXXX functions, the keword 'this' is set to the current socket or callback object. The same applies for RS232 Serial onXXXX functions as well.
As a result, your code socket.read() is functionally equivalent to this.read().
I provided a post discussing such concepts quite a while back. If you want to read more, do a search for +serial +this +keyword and see the posts that come up (first one contains original discussion).
.
|
Lyndel McGee Philips Pronto Addict/Beta Tester
|
|
Post 9 made on Monday March 23, 2009 at 18:29 |
Barry Gordon Founding Member |
Joined: Posts: | August 2001 2,157 |
|
|
Macdomm2, Pronto manual is correct. The unqualified read or write is NOT in scope.
Lyndel, but without the "this." qualifier the partial reference to read or write is meaningless; correct?
|
|
Post 10 made on Monday March 23, 2009 at 20:36 |
Lyndel McGee RC Moderator |
Joined: Posts: | August 2001 12,999 |
|
|
I believe read() or write() has ALWAYS worked when in the immediate callback function. When the remote invokes a callback, it sets the scope to be that of the javascript object to which the callback is attached.
|
Lyndel McGee Philips Pronto Addict/Beta Tester
|
|
Post 11 made on Monday March 23, 2009 at 23:42 |
Barry Gordon Founding Member |
Joined: Posts: | August 2001 2,157 |
|
|
Could be, as I said I always qualify a reference so I would never know
|
|
Post 12 made on Tuesday March 24, 2009 at 22:42 |
Lyndel McGee RC Moderator |
Joined: Posts: | August 2001 12,999 |
|
|
On March 23, 2009 at 23:42, Barry Gordon said...
Could be, as I said I always qualify a reference so I would never know Me too. But it makes it nice to know because a socket is nothing more than a javascript object so you can attach the partial response string to a member field of the socket such that you don't need extra variable. socket.onData = function() { this.partialData += this.read(); // check partial data and if end of message is complete extract your part, // process and clear partial data. var toRemove = processMessage(this.partialData); this.partialData = this.partialData.substring(toRemove); }
|
Lyndel McGee Philips Pronto Addict/Beta Tester
|
|
|
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.
|
|