Posted: Thu Jan 26, 2006 11:35 am Post subject: Downloading a file from the internet
Hey, I'm just wondering if it's possible in turing to download a file from the internet? I wanted to have a section in my program that would download the latest update when you click a button, but I haven't had any experience with Turing and the internet.. so is it possible?
Sponsor Sponsor
neufelni
Posted: Thu Jan 26, 2006 11:59 am Post subject: (No subject)
code:
if not Sys.Exec ("http://www.google.com"/*put any website here */) then
put "Error"
end if
[/quote]
skootles
Posted: Thu Jan 26, 2006 12:07 pm Post subject: (No subject)
Thanks , that will work, but I'm just wondering how would I use that to download .txt and image files too? Because when I just use that, they open up in IE.
Tony
Posted: Thu Jan 26, 2006 12:58 pm Post subject: (No subject)
I just did a quick mod to that other program. I just don't know why this doesn't work
r0ssar00
Posted: Thu Jan 26, 2006 2:56 pm Post subject: (No subject)
whats the error message, something about illegal char in string, if im correct?
skootles
Posted: Thu Jan 26, 2006 3:01 pm Post subject: (No subject)
Sorry for double post, but I get an error in the bottom right of my screen that says "General Protection (seg" (it gets cut off) that displays for about a milisecond, then the program terminates.. I really have no clue whats going wrong
Tony
Posted: Thu Jan 26, 2006 9:20 pm Post subject: (No subject)
a crude approach to step-testing would be to paste your program into a new file one line at a time, and see how far your code works before you get your General Error
Once you know what line of code produces the error, it will be easier for you and others to figure out the cause
Posted: Fri Jan 27, 2006 12:53 am Post subject: (No subject)
Hmm.. Well, when I run the original program:
code:
procedure playMP3
loop
Music.PlayFile ("test.mp3")
end loop
end playMP3
procedure streamMP3 (url : string)
var count : int := 0
var progress : int
var netStream : int
var net_line : char
netStream := Net.OpenURLConnection (url)
if netStream <= 0 then
put "Unable to download mp3 ", url, "!"
return
end if
var fileNo : int
open : fileNo, "test.mp3", write
loop
exit when eof (netStream)
count += 1
locate (1, 1)
progress := round ((62000 - count) / 1000)
put "Downloading Count Down:",progress
get : netStream, net_line
write : fileNo, net_line
end loop
Net.CloseConnection (netStream)
close : fileNo
playMP3
end streamMP3
I get the error that appeared in the bottom of my screen, but as a regular turing error. (The error is "General protection (segmentation) fault", and it highlights the line "Net.CloseConnection (netStream)".
When I run "my program", and trace it, it stops at "exit when eof (netStream)", and it doesn't terminate the program.
skootles
Posted: Fri Jan 27, 2006 12:54 am Post subject: (No subject)
Whoops, forgot that I had over half of it commented
When I trace it, it give me the same error as the other program.
ecliptical
Posted: Sat Jan 28, 2006 11:44 pm Post subject: (No subject)
The error you're having is a turing enternal error...i wrote my own GetUrl Module sending my own HTTP headers and everything and accessing Google still crashed turing...if you're testing it's best not to test with Google...use some other website...i know yahoo works...
Tony
Posted: Sun Jan 29, 2006 1:35 am Post subject: (No subject)
some sites (including CompSci.ca) check to see if connection is made by a browser (FireFox, Safari, IE, etc) or a bot, and respond differently. Turing's request would be identified as a bot, and some sites might break on you.
Posted: Sun Jan 29, 2006 1:58 am Post subject: (No subject)
Ahh, that makes sense. However, I used to have a program like this in VB, that did the same thing. I accidentally deleted the project files, but I wanted to try and make it in a language I know fairly well anyways. Part of that program downloaded sets of image files (from my hosting), and when I tried downloading the same sets, it didn't work. So wouldn't it have detected the other program as a bot?
Tony
Posted: Sun Jan 29, 2006 2:02 am Post subject: (No subject)
I can't say for sure
you could test things out locally by setting up your computer to act as a server. This way you know exactly what's happening on serverside as well