
-----------------------------------
echeese
Sat Nov 22, 2003 12:44 am

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\necheese"
    close (ns)
end loop


I'm hoping to get my first bits on this :D
Basically, everything outputted is echeese
If you change the length, you also have to change the Content-length

-----------------------------------
Tony
Sat Nov 22, 2003 12:50 am


-----------------------------------
say wha? :shock: a webserver writen in turing? I'd like to see that work.

-----------------------------------
echeese
Sat Nov 22, 2003 12:58 am


-----------------------------------
Go right ahead, run it and go to http://localhost/

-----------------------------------
Tony
Sat Nov 22, 2003 1:19 am


-----------------------------------
ohh... thats good :D 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

-----------------------------------
Homer_simpson
Sat Nov 22, 2003 2:25 am


-----------------------------------
well it doesn't work on my computer or else i would have gave u bits for yer creativity...

-----------------------------------
Tony
Sat Nov 22, 2003 2:29 am


-----------------------------------
what you do is you take out the reading input part :lol: and it works.

-----------------------------------
Homer_simpson
Sat Nov 22, 2003 2:57 am


-----------------------------------
u mean like this:
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\necheese" 
close (ns) 
end loop  

nope still doesn't work... :s

-----------------------------------
Tony
Sat Nov 22, 2003 3:18 am


-----------------------------------
i donno homer... works perfectly for me. Well other then the fact that I have to download the file :roll: 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

-----------------------------------
echeese
Sat Nov 22, 2003 9:30 am


-----------------------------------
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
Sat Nov 22, 2003 10:02 am


-----------------------------------

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
Sat Nov 22, 2003 2:42 pm


-----------------------------------
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
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
Sat Nov 22, 2003 3:18 pm


-----------------------------------
and here's an improved version that reads files that have lines with more than 255 characters... pretty bugless...
const ctimeout := 100
function unlock (c : char, s : string, var cond : int) : boolean
    if cond =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
Sun Nov 23, 2003 12:28 pm


-----------------------------------
wow amazing!

im uninstall Apache dis instant!

-----------------------------------
rizzix
Sun Nov 23, 2003 12:42 pm


-----------------------------------
lol what?  :lol:

-----------------------------------
Andy
Sun Nov 23, 2003 4:03 pm


-----------------------------------
nice!

-----------------------------------
echeese
Tue Nov 25, 2003 8:32 am


-----------------------------------
All your bits are belong to me :P

-----------------------------------
Dan
Tue Nov 25, 2003 6:11 pm


-----------------------------------
i most say this was a very good idea. i mean i whould have never thougth up of using turing's net comands to make a web server, i ushley just uses them to piss Amailer off by give other poleops sites hits (inside joke)  :twisted:

-----------------------------------
hackman
Wed Nov 26, 2003 11:49 am


-----------------------------------
echeese-Aurthor Voaden's finest. Best programer here. You dont know who this is do you? Heres a hint- Today is my first day in class all week.

-----------------------------------
Canadian Rob
Wed May 19, 2004 4:29 pm


-----------------------------------
woo nice nice  :lol:

-----------------------------------
guruguru
Wed May 19, 2004 6:36 pm


-----------------------------------
Its nice... but please dont bring up old topics. I doubt the original poster even visits these forums anymore.

-----------------------------------
Canadian Rob
Wed May 19, 2004 8:18 pm


-----------------------------------
lol sry, I use the search 2 much hahah  :cry:

-----------------------------------
beard0
Wed May 26, 2004 10:20 am

binary file
-----------------------------------
And another thing... Is it possible to open binary files in turing? 

yes, turing can read binary files, use:

open : fnum, file, read

instead of

open : fnum, file, get 


-----------------------------------
the_short1
Mon May 31, 2004 6:43 pm


-----------------------------------
wow... well im glad he opened it up!!

i learned something new


Net.LineAvailable (ns) then
get : ns, data : * 


i cam send CHAR.... but it was not working for line and it made me so pissed off...

problem was.... i didn't add :* to it... or at least i dont think i did..



anyways...
this is cool.... me have to try this out!!!

-----------------------------------
the_short1
Mon May 31, 2004 7:23 pm


-----------------------------------
what and how is this sposed to work.....



can u host files off ur PC to the WWW using this?
how do u host files if thats posible...

-----------------------------------
DanShadow
Mon Jul 26, 2004 7:07 pm


-----------------------------------
Damn! I dont have Turing on this computer! Can somebody compile and post this please! Id really like to try it! A webserver in Turing...wow!

-----------------------------------
the_short1
Tue Jul 27, 2004 6:27 pm


-----------------------------------
here dan shadow.. try this....




BadBlue!
works great... password protect folders..  or public ones....    users...   uploading (can diable) ....    p2p if u want...   has a search thing... to search for files in any of ur shared folders..... works with www.DynDNS.org 