
-----------------------------------
skootles
Fri Jan 27, 2006 10:25 pm

Downloaded files are unviewable
-----------------------------------
Okay, so I already made a post about this, I'm trying to make it so the user can update parts of the program by clicking buttons and yadda yadda yadda.. the files are downloaded to their computer. Ok, so I came up with this:

var url : string := "http://www.microsoft.com/resources/design/images/pop_img_mob_01.jpg"
var netStream : int

var file : char
var filenum : int

netStream := Net.OpenURLConnection (url)

if netStream = 0 then
    put url, " could not be located."
    return
end if

open : filenum, "TestFile.jpg", put


loop
    exit when eof (netStream)
    get : netStream, file
    put : filenum, file..
end loop

Which does work..  except the output image is slightly larger that the test one I'm using, and I'm unable to view it. In anything. Can anyone tell me what's going wrong here? Thanks!

-----------------------------------
Tony
Sat Jan 28, 2006 12:56 am


-----------------------------------
you're reading it line by line as text. save your JPEG as TXT and then back, see if you get any corruption. Amplified by Net.'s tendency to loose information, you could run into fatal problems.

Two ideas:

1 -- read/write instead of get/put
2 -- validation. Run some checksum comparisons to ensure that correct content has been downloaded.

-----------------------------------
skootles
Sat Jan 28, 2006 10:33 am


-----------------------------------
I replaced "put" with "write" and it works great!  :)
+ bits.

But there's just one issue..  when I try and get files that have more than one "." in them  (for example, gal.water.ap.jpg), it doesn't seem to work.

var url : string := "http://bb.domaindlx.com/Plixo/gal.water.ap.jpg"
var netStream : int
var file : char
var filenum : int
netStream := Net.OpenURLConnection (url)

if netStream = 0 then
    put url, " could not be located."
    return
end if

open : filenum, "postfile.jpg", write

loop
    exit when eof (netStream)
    get : netStream, file
    write : filenum, file
end loop

-----------------------------------
Tony
Sat Jan 28, 2006 5:17 pm


-----------------------------------
well my guess would be that Turing confuses what part of a.b.c is the actual extension and might be dropping something..

for a fun experiment, upload 2 files into the same folder
a.b
a.b.c

try to download a.b.c with Turing and see if you end up with a.b or not

The thought of bits is appreciated, but notice the
http://www.compsci.ca/v2/rankm.gif
 :wink:

-----------------------------------
md
Sat Jan 28, 2006 6:02 pm


-----------------------------------
Try echoing what you receive to teh screen too... My experience with turing's netwrking code is nil, but unless it's handling ALL of the http protocol stuff for you there might be more you need to do.

-----------------------------------
skootles
Sat Jan 28, 2006 11:48 pm


-----------------------------------
Well, I uploaded these files:

a.b.jpg
a.jpg
b.jpg
a.b

And made it try to get "a.b.jpg", but it didn't seem to get any of those...  so I tried what cornflake said:
Try echoing what you receive to teh screen too... My experience with turing's netwrking code is nil, but unless it's handling ALL of the http protocol stuff for you there might be more you need to do.
and got this:
http://img87.imageshack.us/img87/1360/error8cf.jpg
Strangely, when I try to get and .gif file, I get this:
http://img87.imageshack.us/img87/2535/error29zg.jpg
So maybe it's a turing thing? Because turing doesn't support .gif files...

-----------------------------------
md
Sun Jan 29, 2006 12:12 am


-----------------------------------
As I thought, it's just connecting to the server, if you want to get pages from an HTTP server you need to speak HTTP to it. I don't know of a good resource of hand for that, but google does wonders :)

-----------------------------------
skootles
Sun Jan 29, 2006 12:22 am


-----------------------------------
Ahh..   this is getting increasingly complicated   :P
I had this all nice in VB, but it had a few bugs, and I accidentally deleted the project file    :oops:

-----------------------------------
md
Sun Jan 29, 2006 12:51 am


-----------------------------------
I think if you connect to the server after it sends you some stuff you can send it a GET command (syntax unsure), which should get you another http header and the file.

-----------------------------------
Tony
Sun Jan 29, 2006 1:38 am


-----------------------------------
skootles -- I've just posted in your other Internet files thread. CompSci.ca recognizes bot connections and filters them out. You'd get errors if you try to connect to files hosted on our domain from Turing.

-----------------------------------
md
Sun Jan 29, 2006 3:03 am


-----------------------------------
skootles -- I've just posted in your other Internet files thread. CompSci.ca recognizes bot connections and filters them out. You'd get errors if you try to connect to files hosted on our domain from Turing.
Not so! If you tell the server your user-agent is something that compsci recognizes as non-bot then it won't think so at all! It's just a matter of speaking HTTP and saying the right things.

-----------------------------------
Dan
Sun Jan 29, 2006 4:34 am


-----------------------------------
It is also about what file you are trying to play with and how many times you try to call it. Also about what chars you use in your url line and what syboles are in it.

-----------------------------------
ecliptical
Tue Jan 31, 2006 2:07 am


-----------------------------------
I think I'm perhaps one of the more active/willing Net module people...so here's my contribution the net code you're looking for is 

var requestString := "GET /" + htmlpage + " HTTP/1.1"' + char(10) + "Host: " + hostname;
var fullrequestString := requestString + char(10) + "Accept: */*'"+ char(10) +  "'Connection: close" + char(10) + char(10);

You can't use the default Net.OpenURLConnection unless you modify the turing module to include "put" so you can send... otherwise use Net.OpenConnection (on port 80) 

Also you might want to weed out some of the html crud you'll get so here is a very dirty and quick HTML Parser(not really more like a HTML Stripper)



var flag:boolean
  exit when eof (netStream)
        get : netStream, net_line
  if net_line = "" then
      flag := false
    end if
        if not flag and net_line not= ">" and net_line not= "