John Labenski <jlaben...@gmail.com> wrote: (10/08/2010 19:28) > >On Tue, Aug 10, 2010 at 10:05 AM, Lostgallifreyan <z.c...@btinternet.com> >wrote: >> Can anyone tell me why this fails? > >Unfortunately no, but http://www.google.com and yahoo.com work fine. >
For a moment there I took that to be a terse recommendation for searching. :) >> It seems that while the code 'CanRead()' the URL's stream just fine, it >> cannot actually 'Read()' it at all! >> Substituting other URL and direct file references, even local ones, works >> fine, as does a directly fetched >> copy of the page I'm after, stored locally. It is impossible to read this >> stream directly from the remote source. >> Why? >> >> function HTTP_GET(URL) local T,S={} >> S=wx.wxURL(URL):GetInputStream() while S:CanRead() do >> table.insert(T,S:Read(64)) end >> return table.concat(T) >> end >> >> >> HTTP_GET("http://www.metoffice.com/satpics/latest_uk_ir.html") > >I recommend making the wxURL object local so that it is more obvious >that it will be destroyed, otherwise it will be global. Thanks. I'd only called it three times in the run-life of that script, but I will do it. >The print >statement below says that 0 bytes were read, but that there was >wxURL_NOERR. I think there is a website that will tell you what >webserver is used for any given site, maybe there's something off with >their server? > Could be, though beyond me to know, I think. Other pages from them work ok, but by the time I see one it obviously worked ok. :) Nothing on the otherwise-fetched problem page shows a reason for this. >function iff(a, b, c) if a then return b else return c end end > >function HTTP_GET(URL) > local T = {} > local U = wx.wxURL(URL) -- Make local > local S = U:GetInputStream() > local i = 1 > while S:CanRead() do > a = S:Read(64) > print(string.format("%d: %d : %d : Err %d : '%s'\n", i, S:LastRead(), > iff(S:Eof(), 1, 0), U:GetError(), a)) > table.insert(T,a) > i = i + 1 > if i == 10 then break; end > end > > return table.concat(T), T > end > Nice use of string.format(), I'd been using concatenation .. and quotes a lot for making text phrases from variables and always thought it was a bit graceless, this is better for anything more than one or two variables.. Some good URL-related functions to explore too. I take the point about no error shown. Hard to imagine that wxLua has any reason to do other than try to persist if it is told there is no reason not to. Might be good to have a timeout though, I was forcing it off with Ctrl-Alt-Del because it chewed all available CPU and nothing else would respond during its attempts. There might be something I can write in wxLua code for this, I'm not very familiar with it. so I might have missed something. For now I'm using a small find called HTTP_GET.exe to get the file, as I have a RAM disk for temp files, speed won't be a problem, or clearout at boot. But seeing DOS window popups is NOT tidy. :) ------------------------------------------------------------------------------ This SF.net email is sponsored by Make an app they can't live without Enter the BlackBerry Developer Challenge http://p.sf.net/sfu/RIM-dev2dev _______________________________________________ wxlua-users mailing list wxlua-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/wxlua-users