Posted: 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
Basically, everything outputted is <h1>echeese</h1>
If you change the length, you also have to change the Content-length
Sponsor Sponsor
Tony
Posted: Sat Nov 22, 2003 12:50 am Post subject: (No subject)
say wha? a webserver writen in turing? I'd like to see that work.
Posted: 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
Posted: 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 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
Posted: 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
Posted: 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
Posted: 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
Posted: Sun Nov 23, 2003 12:28 pm Post subject: (No subject)
wow amazing!
im uninstall Apache dis instant!
rizzix
Posted: Sun Nov 23, 2003 12:42 pm Post subject: (No subject)
lol what?
Andy
Posted: Sun Nov 23, 2003 4:03 pm Post subject: (No subject)