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:
Problem with TCP Socket Connection
This thread has 5 replies. Displaying all posts.
Post 1 made on Thursday January 8, 2009 at 18:28
gdixon
Lurking Member
Joined:
Posts:
January 2009
4
Guy I have to admit I'm hunting around a little in the dark here so I'm coming to the gurus to seek some assistance.

Basically I'm streaming music from iTunes on a server. I have an apple script that extracts the mp3 track image out of the currently playing music file and drops it on the web server as a jpg and takes the currently playing track data and drops it into a tiny html file. This all is then offered up to the Pronto 9400 via the Apache web server running on the same box.

My pronto 9400 then runs the following script which is able to successfully bring the image and data across and display it (actually is is just like an iPod now :-) however the problem I have I can only do this one time. Subsequent attempts will generate an error unless I switch to another device and back again to do it one further time etc.

At the Device level, I have the following script:


var socket1 = new TCPSocket(false);
var socket1Result = "";
socket1.onConnect = function()
{
socket1.write("GET " + serverPageName + " HTTP/1.0\r\n\r\n");
socket1Result = "";
}
socket1.onData = function()
{
socket1Result += socket1.read();
}
socket1.onClose = function()
{
t1 = socket1Result.indexOf("Title: ", 0)+7;
t2 = socket1Result.indexOf("<\/txt>",t1);
System.setGlobal("MusicNowPlayingTrack", socket1Result.substring(t1,t2) );
t1 = socket1Result.indexOf("Artist: ", 0)+8;
t2 = socket1Result.indexOf("<\/txt>",t1);
System.setGlobal("MusicNowPlayingArtist", socket1Result.substring(t1,t2) );
t1 = socket1Result.indexOf("Album: ", 0)+7;
t2 = socket1Result.indexOf("<\/txt>",t1);
System.setGlobal("MusicNowPlayingAlbum", socket1Result.substring(t1,t2) );
t1 = socket1Result.indexOf("Rating: ", 0)+8;
t2 = socket1Result.indexOf("<\/txt>",t1);
System.setGlobal("MusicNowPlayingRating", socket1Result.substring(t1,t2) );
playTrackShowStatus("IPOD");
socket1.close();

}


var socket2 = new TCPSocket();
var socket2Result = "";
socket2.onConnect = function()
{
socket2.write("GET " + serverImageName + " HTTP/1.0\r\n\r\n");
socket2Result = "";
}
socket2.onData = function()
{
socket2Result += socket2.read();
}
socket2.onClose = function () {
// remove the HTTP information from the received data
var imageStartIndex = socket2Result.indexOf("\r\n\r\n");
System.setGlobal("MusicNowPlayingCover", socket2Result.substring(imageStartIndex+4) );
playTrackShowStatus("IPOD");
socket2.close();
}




function playTrackShowStatus (thisPage)
{

page(thisPage).widget("NOWPLAYING_TRACK").label = System.getGlobal("MusicNowPlayingTrack");
page(thisPage).widget("NOWPLAYING_ARTIST").label = System.getGlobal("MusicNowPlayingArtist");
page(thisPage).widget("NOWPLAYING_ALBUM").label = System.getGlobal("MusicNowPlayingAlbum");
page(thisPage).widget("NOWPLAYING_RATING").label = System.getGlobal("MusicNowPlayingRating");
page(thisPage).widget("NOWPLAYING_PLAYLIST").label = PlayList[playListSelected];

// make and display the image
var MyImage = new Image( System.getGlobal("MusicNowPlayingCover") );
page(thisPage).widget("COVERART").setImage(MyImage);

}


function playTrackGetStatus()
{
socket1.connect( serverAddressName, 80, 3000);
socket2.connect( serverAddressName, 80, 3000);

}


I then activate the script by firing the playTrackGetStatus function. I'm sure it is something to do with how I am opening the socket and not closing it however it is probably also related to how I am doing things because it feels that no matter where I try and destroy the sockets, then I cannot even activate them the first time as well. Any help would VERY much appreciated! Thank you!!
Post 2 made on Thursday January 8, 2009 at 23:39
PS2
Long Time Member
Joined:
Posts:
October 2005
76
A few observations. The socket.onClose() function should not call socket.close(). The socket cannot be used anymore after onClose() has been called; free the socket by assigned null to the socket and create a new socket.
Post 3 made on Friday January 9, 2009 at 00:13
tenchi
Long Time Member
Joined:
Posts:
January 2006
156
So instead of socket2.close();

socket2 = null;



On January 8, 2009 at 23:39, PS2 said...
A few observations. The socket.onClose() function should
not call socket.close(). The socket cannot be used anymore
after onClose() has been called; free the socket by assigned
null to the socket and create a new socket.
OP | Post 4 made on Saturday January 10, 2009 at 00:52
gdixon
Lurking Member
Joined:
Posts:
January 2009
4
Guys thanks so much for your help. I changed the code per your suggestions but the other issue was the way I was running it. I have now taken the whole code and put it under a button so a quick press will refresh it and I can repetitively do this without any failure. Under the button I then changed the 'playTrackGetStatus' to the 'onRelease' event function name and presto, it works perfectly!

The next stage is to move it from a button it into a constantly refreshing script so that if the system is in music 'play' mode, then it will grab the content from the server and refresh it continuously. Looks like the Pronto Pro iPod on Mac iTunes is about to be born!!

Thanks again!

Greg
Post 5 made on Saturday January 10, 2009 at 04:09
posts
Long Time Member
Joined:
Posts:
March 2007
40
You could have a look at http://dacp.jsharkey.org/ as an alternative way of solving the problem. This is essentially the reverse engineering of the DACP protocol used by the Remote application on an iPhone or iTouch to control iTunes. I have been playing with it and with some minimial success so far. Requires probably better programming skills than I have!
Simon
Post 6 made on Sunday January 11, 2009 at 15:48
Jon Welfringer
Long Time Member
Joined:
Posts:
December 2002
175
Greg,

I would be interested in seeing your revised code. I am doing a Tivo implementation that has issues with TCP disconnects and I'm wondering if I could learn something from your code.

- Jon


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