Topic: SendAndLoad problems...

Hi Chumbysphere....

I'm working on a 'server status' widget which uses sendAndLoad method to call a small php file on my server. 

The problem is, when running on my Chumby, the sendAndLoad doesn't seem to fail.  In other words, if I remove to the php file from my server, sendAndLoad should fail, but it only fails when the widget is running my local machine and the "now playing" page.   

It's important that the sendAndLoad fail, because this will be an indication that the server is down. smile

Judging by the speed, it appears that the Chumby network might be caching all http traffic, so perhaps http errors (404) aren't be relayed properly back to the Chumby?

Thanks!

Re: SendAndLoad problems...

You'l need to either:

1) make sure the HTTP response headers from your server set the "Cache-Control" header to indicate it should not be cached.
2) ...or add some random or time-based parameters to the URL in order to defeat the cache.

The second option is typically something like:

blah.sendAndLoad('http://www.example.com?nocache='+(new Date()).getTime(),response);

Re: SendAndLoad problems...

Duane, thanks for the quick reply.  I've added the no cache code (thanks), but that still doesn't fix the problem.  The onLoad function still return a positive success for a 404 page.  In fact, it appears to load the contents of the 404 html page as a var name...

Is it possible that when the "chumby network" is proxying the page and isn't forwarding the correct headers back to my little chumby?

I've come up with a workaround for now.  Instead of testing the "success" var in the onLoad, I'm just looking for a var that the php script should be sending (and I'm clearing it before I call the sendAndLoad again)... Seems to work.

Ryan

Re: SendAndLoad problems...

The "chumby network" isn't proxying your request - it's all between your chumby and your server.

I think this is an issue with Flash Lite - we had another developer that reported a similar issue with different Flash Lite device.

Re: SendAndLoad problems...

OK, thanks for the info..
I hope you guys are all safe out there.
Ryan

Re: SendAndLoad problems...

a slight improvement on checking for the PRESENCE of a set-and-cleared variable would be to have your server send the time of day as a variable; the widget could compare that against what it thinks the time is and fail if the delta is larger than some reasonable threshold.  that way it will guard against any caching anywhere in the path. 

of course, you'd have to deal with time zones and etc but it could be a little more robust than just checking for the presence of a static variable.

Re: SendAndLoad problems...

thanks..

Also -- Duane, what category should I post this widget to?  (It's called 'Server Up Time' and it checks a webserver for uptime and average load).

Re: SendAndLoad problems...

Yikes - good question.

I'll consult with some of the folks here and see if we should create a new category for stuff like this.  Unfortunately, the fellow in charge of widgets evacuated with his family to Orange County somewhere, but should be coming back this afternoon.

Re: SendAndLoad problems...

dnkorte wrote:

of course, you'd have to deal with time zones and etc but it could be a little more robust than just checking for the presence of a static variable.

Actually, if both the server and the client use UTC for this, then all should be good no matter the timezone.

Re: SendAndLoad problems...

I have a whole lot of widgets I'll be posting like this.  We need a category bad.  Mine have meters and gauges that will show things.  Right now I've kept them private, but when I put them into Public a good category would be nice.

Re: SendAndLoad problems...

Any suggestions for the name of this category?

Re: SendAndLoad problems...

Networking & Security

(ripped from Apple's widget categories)

Re: SendAndLoad problems...

Hey Duane.. Any ETA on a new category or should I post this somewhere else? I'm eager to publish my first Chumby widget! smile

Re: SendAndLoad problems...

The "Networking & Security" category has been created.

Re: SendAndLoad problems...

ryanc wrote:

Hey Duane.. Any ETA on a new category or should I post this somewhere else? I'm eager to publish my first Chumby widget! smile

I want your widget on my Chumby smile

Re: SendAndLoad problems...

Veilkrand wrote:

I want your widget on my Chumby smile

Cool!  I just made it public, but I'm sure someone will need to review and approve..

Meanwhile, make me a "chum" and I'll try to send it to you.  My username is rcarrington

http://www.chumby.com/chums/add

Re: SendAndLoad problems...

I nearly posted this as a new thread and found this one at the last minute.  I am having this exact same problem.  The 404 isn't getting recognized on the Chumby's Flash player.  I tried publishing as Flash 8 and Flash Lite 2.0 and had the same problem.

I have a simple image viewer that I wrote and it works fine.  It pulls a new image from my webserver every 10 seconds.   I'm trying to have all the proper error handling in place in case my webserver goes down/etc.  Unfortunately the onLoadError() event does not seem to be triggered like it should when ran on the Chumby.  I am adding/deleting my randomphoto.php api file on my webserver in order to trigger the expected success/fail condition.  onLoadError() is triggered properly if I delete my api file on the webserver, then run the swf on my pc's flash player.   My test actionscript code is at the bottom.

Here is the Chumby console debug, you will notice that "load complete" and "load init" are triggered, despite the fact that the request should have failed.  It looks like the Flash Player is then trying to parse the 404 page's contents as an image file.

Webserver api file removed (should trigger an error):

2007-12-15 12:35:59 NetStreamRequest::Open(1): Opening protocol 'http://' host 'www.lunky.com' port 80 location '/randomphoto.php?79990487'
2007-12-15 12:35:59 NetStreamRequest::Open(1) opened http object id 6
2007-12-15 12:36:00 NetStreamRequest::ProcessHeaders(1) content-type: text/html; charset=iso-8859-1
2007-12-15 12:36:00 NetStreamRequest::Step(1) done, closing stream (208 of 208 bytes, avail=0) status=200
2007-12-15 12:36:00 SI_Object::SI_GetImageInfo(40a2b5d4,1084454432,{40a37200,208})
2007-12-15 12:36:00 ImageObject::DetectImage() unable to determine type of image with 208 bytes starting 3c 21 44 4f
2007-12-15 12:36:00 ImageObject::DetectImage() unable to determine type of image with 208 bytes starting 3c 21 44 4f
2007-12-15 12:36:00 SI_Object::SI_GetImageInfo() - Image id 1084454432 type 0 (Unknown) not supported
2007-12-15 12:36:00 SI_NotifyError(0x40a2b5d4): Error 6 (FI_BadImageDataError)
2007-12-15 12:36:00 TRACE: Load Complete
2007-12-15 12:36:00 TRACE: Load init
2007-12-15 12:36:00 ClientObject::DoUpdate(id=5 master=n): got FI_FrameBufferNotUpdatedWithError

Webserver api file in place (should trigger a success):

2007-12-15 12:42:00 NetStreamRequest::Open(1): Opening protocol 'http://' host 'www.lunky.com' port 80 location '/randomphoto.php?91064844'
2007-12-15 12:42:00 NetStreamRequest::Open(1) opened http object id 6
2007-12-15 12:42:00 NetStreamRequest::ProcessHeaders(1) content-type: image/jpeg
2007-12-15 12:42:00 NetStreamRequest::Step(1) done, closing stream (20196 of 0 bytes, avail=0) status=200
2007-12-15 12:42:00 TRACE: Load Complete
2007-12-15 12:42:00 TRACE: Load init

Example Actionscript test code:

rand =  Math.ceil(Math.random(9999999) * 100000000);
this.createEmptyMovieClip('pic_0',this.getNextHighestDepth());

// Load the clip
pic_listener = new Object();
pic_mcl = new MovieClipLoader();

pic_listener.onLoadComplete = function(target_mc:MovieClip) {
    trace("Load complete");
}

    
pic_listener.onLoadInit = function(target_mc:MovieClip) {
    trace("Load init");
    
}
pic_listener.onLoadError = function(target_mc:MovieClip, errorCode:String) {
    trace("Load Error: "+errorCode);
}

pic_mcl.addListener(pic_listener);
pic_mcl.loadClip('http://www.lunky.com/randomphoto.php?'+rand, this['pic_0']);

Re: SendAndLoad problems...

Your server is not responding with any valid HTTP response headers.

Your server:

dmaxwell:~ dmaxwell$ telnet www.lunky.com 80
Trying 64.34.177.223...
Connected to lunky.com.
Escape character is '^]'.
GET /blah
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>401 Authorization Required</title>
</head><body>
<h1>Authorization Required</h1>
<p>This server could not verify that you
are authorized to access the document
requested.  Either you supplied the wrong
credentials (e.g., bad password), or your
browser doesn't understand how to supply
the credentials required.</p>
</body></html>
Connection closed by foreign host.

Normal server:

dmaxwell:~ dmaxwell$ telnet www.chumby.com 80
Trying 209.34.82.226...
Connected to chumby.com.
Escape character is '^]'.
GET /blah

HTTP/1.0 400 Bad Request
Connection: close
Content-Type: text/html
Content-Length: 349
Date: Sat, 15 Dec 2007 21:40:35 GMT
Server: lighttpd/1.4.18

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
         "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
 <head>
  <title>400 - Bad Request</title>
 </head>
 <body>
  <h1>400 - Bad Request</h1>
 </body>
</html>
Connection closed by foreign host.

Note the chumby server includes a valid HTTP response header, which indicates the error code.  Since your server doesn't do that, the client really has no choice but to interpret the response as a 200 OK or reject it entirely, which is confirmed in the log as "status=200".  HTTP clients are not expected to dig through the content of the response to pick out some embedded text which might be interpreted as an error.

If this behavior continues after you've fixed your server, please let us know.

Re: SendAndLoad problems...

Hmm, I'll have to look into that issue with my server.  I was wondering about that originally and with liveHTTPheaders with Firefox I was getting a proper 404 header so I didn't pursue it further.

In the meantime though, this problem still persists, I tried pulling a non-existent image off of a couple other websites (including www.chumby.com) and still had the same issue.  The flash player sees it as a success and thus trying to parse the received data as an image.

2007-12-15 17:47:21 NetStreamRequest::Open(1): Opening protocol 'http://' host 'www.chumby.com' port 80 location '/asdf?8690420'
2007-12-15 17:47:21 NetStreamRequest::Open(1) opened http object id 6
2007-12-15 17:47:21 NetStreamRequest::ProcessHeaders(1) content-type: text/html; charset=utf-8
2007-12-15 17:47:21 NetStreamRequest::Step(1) done, closing stream (190 of 190 bytes, avail=0) status=200
2007-12-15 17:47:22 SI_Object::SI_GetImageInfo(40a2b5d4,1084463408,{40a39830,190})
2007-12-15 17:47:22 ImageObject::DetectImage() unable to determine type of image with 190 bytes starting 3c 21 44 4f
2007-12-15 17:47:22 ImageObject::DetectImage() unable to determine type of image with 190 bytes starting 3c 21 44 4f
2007-12-15 17:47:22 SI_Object::SI_GetImageInfo() - Image id 1084463408 type 0 (Unknown) not supported
2007-12-15 17:47:22 SI_NotifyError(0x40a2b5d4): Error 6 (FI_BadImageDataError)
2007-12-15 17:47:22 TRACE: Load complete
2007-12-15 17:47:22 TRACE: Load init

I'm running: HW 3.7 SW: 1.2 FW: 396 if that helps any.

Re: SendAndLoad problems...

OK, we'll take a look at the code and see what's up.

Re: SendAndLoad problems...

OK, we've confirmed a bug, and have filed it.  Should be fixed in a future firmware release.

Re: SendAndLoad problems...

cool, thanks for checking it out.  I'll work around it in the meantime.

Re: SendAndLoad problems...

@ryanc: it just received my chumby and have plenty ideas to use it...
But at the first step I am blocked... As I wrote here: http://forum.chumby.com/viewtopic.php?id=1335 , I've problems with loadVariables function I used many times...but not with chumby...
Because of Flash Lite (or because of me) it does not work...
I tried to use SendAndLoad function but it was not successfull...Could you upload you .fla file somewhere?
Thanks for your attention....