World: r3wp
[!REBOL3 Schemes] Implementors guide
older newer | first last |
DideC 26-May-2010 [2074x4] | I want to build a very very very simple web server in R3. I just want to be able to receive an HTTP request and send the response. But me and Rebol networking are two differents people !! To begin, I just want to be able to display the full request in the response page. So far I have wrote this by peeking code in DocBase, but it does not work as I want : the browser stay awaiting the answer. Can one point me to what's wrong ? |
REBOL [] print "Serving port 8080..." open-subport: func [port] [ print "=== Creating sub-port" port/awake: func [event /local port] [ print ["=== Subport event:" event/type] port: event/port switch/default event/type [ read [ print [" " data: to-string port/data] write port to-binary rejoin ["<html><head></head><body>" data "</body></html>" newline] true ] wrote [read port] close [close port] ] [false] ] ] server: open tcp://:8080 server/awake: func [event] [ print ["*** Server event:" event/type] if event/type = 'accept [ open-subport first event/port ] false ] wait 30 close server print "Done serving" halt | |
Seems I have found my way to make it working : | |
REBOL [] print "Serving port 8080..." open-subport: func [port] [ print "=== Creating sub-port" port/awake: func [event /local port data] [ print ["=== Subport event:" event/type] port: event/port switch/default event/type [ read [ print [" " data: to-string port/data] data: replace/all data newline <br> write port to-binary rejoin ["HTTP/1.0 200 OK^/Content-type: text/html^/^/<html><head></head><body>" data "</body></html>" newline] ] wrote [ close port ] ] [false] ] read port ] server: open tcp://:8080 server/awake: func [event] [ print ["*** Server event:" event/type] if event/type = 'accept [ open-subport first event/port ] false ] wait 30 close server print "Done serving" halt | |
NickA 26-May-2010 [2078] | great! |
Andreas 26-May-2010 [2079] | You might also want to have a look at: http://github.com/earl/rebol3/blob/master/scripts/shttpd.r |
Anton 27-May-2010 [2080] | Ah, you just forgot the http header. |
DideC 27-May-2010 [2081] | Thank's Anton. Can be of some help. |
Anton 28-May-2010 [2082] | (DideC meant to thank Andreas.) |
NickA 28-May-2010 [2083] | I'm very happy to see this being done with R3 :) |
Graham 28-Jun-2010 [2084x2] | Not sure what's happening here .. but my server closes the connection, and termintes the thread, but R3 is not getting a close event. |
Hmm...but I get a close event if the server throws an exception | |
Graham 29-Jun-2010 [2086x2] | db: open jdbcbridge://localhost insert db [{select * from staff where fullname = (?)} "Graham Chiu" ] >> print length? db 1 result: pick db 1 >> print length? db 0 close db db: open jdbcbridge://localhost:8000 insert db {select first 2 * from staff} >> print length? result 2 >> result: copy db >> print length? result 0 close db |
http://github.com/gchiu/Rebol3/blob/master/protocols/prot-jdbcbridge.r | |
Steeve 29-Jun-2010 [2088x2] | I see no evidence in that test. What is the events trace ? |
There are potentially several problems in that code. First, never use wait in the event handler. it's a good way to produce a stack overflow. Second, I have to go to work, sorry... | |
Graham 29-Jun-2010 [2090] | It's so long since I looked at this R3 network stuff ... |
Steeve 29-Jun-2010 [2091] | Last but not least , there is problem in the close event. >>client/spec/data: load enline to-string client/spec/data should probably be >>client/spec/data: load enline to-string client/data |
Graham 29-Jun-2010 [2092x9] | except I'm copying the data from client/data to client/spec/data ... |
and then clearing the client/data | |
I've setup a server at www.compkarori.co.nz:8020 to help debug the jdbcbridge protocol. | |
you don't need any db drivers installed on your side ... it's a tcp connection to the db server. | |
Oh yeah ... don't wipe the Db ... but I've made a backup anyway. It's the demo employee.fdb that comes with firebird. You can do this db: open jdbcbridge://www.compkarori.co.nz:8020 insert db {select first 3 * from employee} result: copy db | |
Ok, updated the protocol to remove the waits inside the handler ... and it is working now. I can now detect the close event from the server. | |
Still don't know if I can reuse the port after the server closes it .. or, whether i need to create a new subport | |
going to think on the syntax to get the database metadata ... as I should be able to get column names, and types | |
Anyone tried this out? | |
Graham 3-Jul-2010 [2101] | What's the best way to determine whether the server has completed sending data if the server does not close the port? |
Steeve 3-Jul-2010 [2102] | like for any protocol, the server must send the length of the data at first |
Graham 3-Jul-2010 [2103x4] | pop uses .crlf ftp closes the data port |
http uses a content-length ... | |
I guess I should try that ... sending a length | |
pop uses crlf.crlf .. sorry | |
Pavel 12-Aug-2010 [2107] | Any simple protocol example available, something like the R2 one long time on rebolforces, but for R3? I'd like to implement protocol above 'file schema. Any help/hint welcome. |
Graham 12-Aug-2010 [2108] | Yes, check my github site |
Pavel 12-Aug-2010 [2109x3] | I've looked at your shemes already, but all of the are network related. Some easy pedagogical example would help me :) how to ommit port numbers (maybe they are not neccesary) and especially how to manage subport in 'file. Anyway impressive bunch of schemes. |
typo all of them | |
may the sheme be asynchrnous alhough file scheme is synchronous (I presume)? | |
Henrik 12-Aug-2010 [2112] | Robert made an overview of how ports work a while ago. I'm not sure if it's available publicly. |
Graham 12-Aug-2010 [2113] | file io is sync isn't it? |
Pavel 12-Aug-2010 [2114x2] | Thats what I wrote |
But ok sub port cannot be unleashed from above schema right? | |
Graham 12-Aug-2010 [2116x2] | why not? |
the main port is just an abstraction .. to allow you to work on the real port | |
Pavel 12-Aug-2010 [2118] | Thats what I ask, may the scheme be asynchronous when low level port is synronous and we dont use tasks yet? |
Graham 12-Aug-2010 [2119] | I don't think so |
Maxim 12-Aug-2010 [2120x2] | I guess we'll need device extensions for briging the gap. |
briging = bridging | |
Pavel 12-Aug-2010 [2122] | Has anybody tried some file related scheme? zip// or somethink like was in disscussion? |
Graham 12-Aug-2010 [2123] | I'm missing what is the point? the network schemes are written to try and emulate file io ... |
older newer | first last |