Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Downloading a file from the internet
Index -> Programming, Turing -> Turing Help
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
skootles




PostPosted: 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
Sponsor
sponsor
neufelni




PostPosted: 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




PostPosted: Thu Jan 26, 2006 12:07 pm   Post subject: (No subject)

Thanks Very Happy , 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




PostPosted: Thu Jan 26, 2006 12:58 pm   Post subject: (No subject)

You'd have to use the Net. module like over here
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
skootles




PostPosted: Thu Jan 26, 2006 1:53 pm   Post subject: (No subject)

Alrighty, well I have this, which should download a google image (just for testing purposes):
code:
var url : string := "http://mail.google.com/mail/help/images/logo.gif"

var count : int := 0
var progress : int
var netStream : int
var net_line : char

netStream := Net.OpenURLConnection (url)

if netStream <= 0 then
    put url, " could not be located."
    return
end if

var filenum : int
open : filenum, "test.gif", 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 : filenum, net_line
   
end loop

Net.CloseConnection (netStream)


I just did a quick mod to that other program. I just don't know why this doesn't work Sad
r0ssar00




PostPosted: 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




PostPosted: 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 Embarassed
Tony




PostPosted: 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
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Sponsor
Sponsor
Sponsor
sponsor
skootles




PostPosted: 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

streamMP3 ("http://72.29.76.231/~eclipti/turing/test.mp3")

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




PostPosted: Fri Jan 27, 2006 12:54 am   Post subject: (No subject)

Whoops, forgot that I had over half of it commented Razz
When I trace it, it give me the same error as the other program.
ecliptical




PostPosted: 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




PostPosted: 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.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
skootles




PostPosted: 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




PostPosted: 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
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
skootles




PostPosted: Sun Jan 29, 2006 2:08 am   Post subject: (No subject)

Well, that sounds like it would take some advanced knowledge.. so I don't think it would do me any good unfortunately.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 2  [ 21 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: