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

Username:   Password: 
 RegisterRegister   
 Most stable webserver written (By me)
Index -> Programming, Turing -> Turing Submissions
Goto page 1, 2, 3  Next
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
echeese




PostPosted: Sat Nov 22, 2003 12:44 am   Post subject: Most stable webserver written (By me)

var p1, ns : int
var netaddress, data : string
p1 := 80
loop
ns := Net.WaitForConnection (p1, netaddress)
loop
if Net.LineAvailable (ns) then
get : ns, data : *
exit when ord (data (1)) = 13
end if
end loop
put : ns,
"HTTP/1.1 200 OK\nCache-control: private\nContent-type: text/html\nContent-length: 15\n\n<h1>echeese</h1>"
close (ns)
end loop


I'm hoping to get my first bits on this Very Happy
Basically, everything outputted is <h1>echeese</h1>
If you change the length, you also have to change the Content-length
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Sat Nov 22, 2003 12:50 am   Post subject: (No subject)

say wha? Shocked a webserver writen in turing? I'd like to see that work.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
echeese




PostPosted: Sat Nov 22, 2003 12:58 am   Post subject: (No subject)

Go right ahead, run it and go to http://localhost/
Tony




PostPosted: Sat Nov 22, 2003 1:19 am   Post subject: (No subject)

ohh... thats good Very Happy too bad IE doesnt recognize output as a webpage, it promps me to download the ASCII file.

some bugs there... first of all, exit when statment causes program to crash since data variable has 0 length. And output is 16 characters, not 15 Wink

its a new consept to turing though - have some bits
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Homer_simpson




PostPosted: Sat Nov 22, 2003 2:25 am   Post subject: (No subject)

well it doesn't work on my computer or else i would have gave u bits for yer creativity...
Tony




PostPosted: Sat Nov 22, 2003 2:29 am   Post subject: (No subject)

what you do is you take out the reading input part Laughing and it works.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Homer_simpson




PostPosted: Sat Nov 22, 2003 2:57 am   Post subject: (No subject)

u mean like this:
code:
var p1, ns : int
var netaddress, data : string
p1 := 80
loop
ns := Net.WaitForConnection (p1, netaddress)

put : ns,
"HTTP/1.1 200 OK\nCache-control: private\nContent-type: text/html\nContent-length: 15\n\n<h1>echeese</h1>"
close (ns)
end loop 

nope still doesn't work... :s
Tony




PostPosted: Sat Nov 22, 2003 3:18 am   Post subject: (No subject)

i donno homer... works perfectly for me. Well other then the fact that I have to download the file Rolling Eyes But still works. Make sure that your firewall allows turing to act as a server then go to http://localhost/

I'm imagining that running an appache or whatnot (any other web server for that matter) will interfere
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Sponsor
Sponsor
Sponsor
sponsor
echeese




PostPosted: Sat Nov 22, 2003 9:30 am   Post subject: (No subject)

Odd... http://localhost brings up a netscape search for localhost, and Im using IE... But http://127.0.0.1 works for me though.
echeese




PostPosted: Sat Nov 22, 2003 10:02 am   Post subject: (No subject)

code:

var p1, ns, fnum, count : int := 0
var netaddress, data, file : string
p1 := 80
file := "index.html"
open : fnum, file, get
loop
    exit when eof (fnum)
    get : fnum, data : *
    put data
    count += length (data)
end loop

loop
    ns := Net.WaitForConnection (p1, netaddress)
    loop
        if Net.LineAvailable (ns) then
            get : ns, data : *
            exit when ord (data (1)) = 13
        end if
    end loop
    put : ns,
        "HTTP/1.1 200 OK\nCache-control: private"
    put : ns, " Content-type: text/html\nContent-length: ", count, "\n"
    open : fnum, file, get
    loop
        exit when eof (fnum)
        get : fnum, data : *
        put : ns, data
    end loop
    close (ns)
end loop


That one can actually load files. The command to get files from http is
GET /file.htm HTTP/1.1
if there is anyone out there that will post some code to get the /file.htm part, I would appreciate it.
And another thing... Is it possible to open binary files in turing?
After I add mime typing, I'm planning on adding image support.
Like maybe, uh, read the ord of a byte and chr it to the browser
Homer_simpson




PostPosted: Sat Nov 22, 2003 2:42 pm   Post subject: (No subject)

i got it fixed...
and i changed a bit of stuff in yer code.... now u can load any file just by going to http://localhost/file.html
code:
function mid (s : string, n1, n2 : int) : string
    var s2 : string := ""
    for i : n1 .. n2
        s2 := s2 + s (i)
    end for
    result s2
end mid

var p1, ns, fnum, count : int := 0
var netaddress, file : string
var data: string
p1 := 80

loop
    ns := Net.WaitForConnection (p1, netaddress)
    loop
        if Net.LineAvailable (ns) then
            get : ns, data : *
            put data
            if mid (data, 1, 3) = "GET" then
                file := mid (data, 6, length (data) - 8)
            end if
            exit when data = "Connection: Keep-Alive"
        end if
    end loop
    put : ns, "HTTP/1.1 200 OK\nCache-control: private"

    open : fnum, file, get
    loop
        exit when eof (fnum)
        get : fnum, data : *
        count += length (data)
    end loop

    put : ns, " Content-type: text/html\nContent-length: ", count, "\n"
    open : fnum, file, get
    loop
        exit when eof (fnum)
        get : fnum, data : *
        put : ns, data
    end loop
    close (ns)
end loop


btw here's 50 bits...
Homer_simpson




PostPosted: Sat Nov 22, 2003 3:18 pm   Post subject: (No subject)

and here's an improved version that reads files that have lines with more than 255 characters... pretty bugless...
code:
const ctimeout := 100
function unlock (c : char, s : string, var cond : int) : boolean
    if cond <= length (s) then
        if c = s (cond) then
            cond += 1
        else
            cond := 1
        end if
        if cond = length (s) + 1 then
            result true
        end if
    else
        result false
    end if
    result false
end unlock
function mid (s : string, n1, n2 : int) : string
    var s2 : string := ""
    for i : n1 .. n2
        s2 := s2 + s (i)
    end for
    result s2
end mid

var p1, ns, fnum, count, cond, cond2, cond3 : int := 1
var netaddress, file : string
var data : char
var datas : string
p1 := 80

loop
    ns := Net.WaitForConnection (p1, netaddress)


    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%Recieving%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    loop
        if Net.CharAvailable (ns) then
            get : ns, data
            put data ..

            if unlock (data, "GET", cond2) then
                loop
                    if Net.LineAvailable (ns) then
                        get : ns, datas : *
                        exit
                    end if
                end loop
                put ""
                put "-----------------Input--------------------"
                put datas
                put "------------------------------------------"
                file := mid (datas, 3, length (datas) - 8)
            end if

            if unlock (data, "Connection: Keep-Alive", cond) then
                exit
            end if
        else
            cond3 += 1
            exit when cond3>=ctimeout
        end if
    end loop
   
   
   
   
   
   
   
   
   
   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%Reading%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    put : ns, "HTTP/1.1 200 OK\nCache-control: private"
    open : fnum, file, get
    loop
        exit when eof (fnum)
        get : fnum, data
        count += 1
    end loop

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%Sending%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    put : ns, " Content-type: text/html\nContent-length: ", count, "\n"
    open : fnum, file, get
    loop
        exit when eof (fnum)
        get : fnum, data
        put : ns, data ..
    end loop
    close (ns)
end loop
vexd




PostPosted: Sun Nov 23, 2003 12:28 pm   Post subject: (No subject)

wow amazing!

im uninstall Apache dis instant!
rizzix




PostPosted: Sun Nov 23, 2003 12:42 pm   Post subject: (No subject)

lol what? Laughing
Andy




PostPosted: Sun Nov 23, 2003 4:03 pm   Post subject: (No subject)

nice!
Display posts from previous:   
   Index -> Programming, Turing -> Turing Submissions
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

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


Style:  
Search: