Computer Science Canada

Most stable webserver written (By me)

Author:  echeese [ 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

Author:  Tony [ Sat Nov 22, 2003 12:50 am ]
Post subject: 

say wha? Shocked a webserver writen in turing? I'd like to see that work.

Author:  echeese [ Sat Nov 22, 2003 12:58 am ]
Post subject: 

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

Author:  Tony [ Sat Nov 22, 2003 1:19 am ]
Post 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

Author:  Homer_simpson [ Sat Nov 22, 2003 2:25 am ]
Post subject: 

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

Author:  Tony [ Sat Nov 22, 2003 2:29 am ]
Post subject: 

what you do is you take out the reading input part Laughing and it works.

Author:  Homer_simpson [ Sat Nov 22, 2003 2:57 am ]
Post 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

Author:  Tony [ Sat Nov 22, 2003 3:18 am ]
Post 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

Author:  echeese [ Sat Nov 22, 2003 9:30 am ]
Post 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.

Author:  echeese [ Sat Nov 22, 2003 10:02 am ]
Post 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

Author:  Homer_simpson [ Sat Nov 22, 2003 2:42 pm ]
Post 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...

Author:  Homer_simpson [ Sat Nov 22, 2003 3:18 pm ]
Post 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

Author:  vexd [ Sun Nov 23, 2003 12:28 pm ]
Post subject: 

wow amazing!

im uninstall Apache dis instant!

Author:  rizzix [ Sun Nov 23, 2003 12:42 pm ]
Post subject: 

lol what? Laughing

Author:  Andy [ Sun Nov 23, 2003 4:03 pm ]
Post subject: 

nice!

Author:  echeese [ Tue Nov 25, 2003 8:32 am ]
Post subject: 

All your bits are belong to me Razz

Author:  Dan [ Tue Nov 25, 2003 6:11 pm ]
Post subject: 

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 Evil

Author:  hackman [ Wed Nov 26, 2003 11:49 am ]
Post subject: 

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.

Author:  Canadian Rob [ Wed May 19, 2004 4:29 pm ]
Post subject: 

woo nice nice Laughing

Author:  guruguru [ Wed May 19, 2004 6:36 pm ]
Post subject: 

Its nice... but please dont bring up old topics. I doubt the original poster even visits these forums anymore.

Author:  Canadian Rob [ Wed May 19, 2004 8:18 pm ]
Post subject: 

lol sry, I use the search 2 much hahah Crying or Very sad

Author:  beard0 [ Wed May 26, 2004 10:20 am ]
Post subject:  binary file

echeese wrote:
And another thing... Is it possible to open binary files in turing?

yes, turing can read binary files, use:
code:

open : fnum, file, read

instead of
code:

open : fnum, file, get

Author:  the_short1 [ Mon May 31, 2004 6:43 pm ]
Post subject: 

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!!!

Author:  the_short1 [ Mon May 31, 2004 7:23 pm ]
Post subject: 

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...

Author:  DanShadow [ Mon Jul 26, 2004 7:07 pm ]
Post subject: 

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!

Author:  the_short1 [ Tue Jul 27, 2004 6:27 pm ]
Post subject: 

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 <its integrated..... works with routers....




.its wicked... the free version only lasts 60 days or something... afta that u can still share files.. but the uploading files thing is diabled (( let other ppl upload files to ur pc))..

but if u find a good place to 'buy' the full version..(or code). errgm... PM me...

Author:  Paul [ Tue Jul 27, 2004 7:15 pm ]
Post subject: 

the keyword here is TURING... he's into the networking in turing... and thats why he wants this program... whats badblue gonna do for him Confused

Author:  the_short1 [ Tue Jul 27, 2004 10:24 pm ]
Post subject: 

good point.. pb.... ill compile tomorow.. its 2 late tonite...

Author:  r0ssar00 [ Thu Oct 07, 2004 10:40 am ]
Post subject: 

here's the compile... :D

Author:  the_short1 [ Thu Oct 07, 2004 2:55 pm ]
Post subject: 

??? ? ? ? ? ? ?? what was that sposed to do?

and it has a error... -10 is not a valid netstream id..

Author:  DanShadow [ Thu Oct 07, 2004 9:02 pm ]
Post subject: 

wow....this is excellent, lol. Im just.....really, impressed, lol.
+50 bits

Author:  r0ssar00 [ Fri Oct 08, 2004 9:22 am ]
Post subject: 

sorry, i meant to post the compiled version...

Author:  zomg [ Tue Oct 12, 2004 11:14 am ]
Post subject: 

nice work man i love this thing
keep up the good work

Author:  the_short1 [ Mon Nov 22, 2004 8:59 pm ]
Post subject: 

ok... i still get an error when running it (the source that was posted.. )... and how would one use this to host a file to the WWW? im lost when it comes to turing's net stuff.. its jsut retarded..

Author:  Viper [ Tue Nov 23, 2004 10:12 am ]
Post subject: 

nothing happened when i ran it Confused Confused Confused


: